`
满城风雨近重阳
  • 浏览: 20790 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

org.hibernate.MappingException: Unknown entity: com.freemark.model.User

阅读更多
org.hibernate.MappingException: Unknown entity: com.freemark.model.User
	at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
	at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1479)
	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
	at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
	at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
	at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
	at com.freemark.dao.UseDao.addUser(UseDao.java:34)
	at com.freemark.controller.FreeMarkController.test(FreeMarkController.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:722)

 遇到如上的报错问题,先展示一下我的User类:

package com.freemark.model;



import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;


import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;
     


@Entity
@Table(name = "t_users")
public class User {

     private String id; 
     private String name; 
     private String password; 
     private Byte isactive; 
     @DateTimeFormat(pattern="yyyy-MM-dd") 
     private Date birth;
  
     @GenericGenerator(name = "generator", strategy = "uuid.hex")
 	 @Id
 	 @GeneratedValue(generator = "generator")
     @Column(name="id", unique=true, nullable=false, length=32)
     public String getId(){
     
     return id;
     
     
    }
    public User(String id){
      this.id=id;
     }
    
    public User(){}
    
    
    public void setId(String id){
    
       this.id=id;
    }
 
    @Column(name="name", length=50)
    public String getName(){
     
     return name;
    }
    
    
    public void setName(String name){
    
       this.name=name;
    }
 
    @Column(name="password", length=50)
    public String getPassword(){
     
     return password;
    }
    
    
    public void setPassword(String password){
    
       this.password=password;
    }
 
    @Column(name="isactive", length=3)
    public Byte getIsactive(){
     
     return isactive;
    }
    
    
    public void setIsactive(Byte isactive){
    
       this.isactive=isactive;
    }
 
    @Column(name="birth", length=10)
    public Date getBirth(){
     
     return birth;
    }
    
    
    public void setBirth(Date birth){
    
       this.birth=birth;
    }
 
	
   
}

 这里要注意Import引入的包名,我这里引入的包名是正确的,这个报错是因为,sessionFactory中没有这个类,解决办法:

<!-- 配置SessionFactory sessionFactory-->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- <property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
		<property name="annotatedClasses">
			<list>
				<value>com.freemark.model.User</value>
			</list>
		</property> -->
		
		<property name="packagesToScan">
			<list> 
				<value>com.freemark.model</value>
			</list>
		</property>
	</bean>

 注意上面红色字体的部分(或者是span标签包住的部分),让sessionFactory来扫描这个包下面的类。问题解决!

 

分享到:
评论

相关推荐

    Spring3.1 集成 JBPM4.4

    NULL 博文链接:https://guoyinjian.iteye.com/blog/1259538

    hibernate错误解决方案

    nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.xindeco.myregister.pojo.MyRegisterInfo column: password (should be mapped with insert="false" update=...

    hudson构建错误及解决方法

    Hudson持续集成工具可以集成Maven工具,并支持其项目的自动化构件,我们可以通过对其配置达到以Maven的形式将构件项目自动化管理起来的目的。

    Hibernate配置常见错误

    错误表现:尝试操作某个实体类时,出现“org.hibernate.MappingException: Unknown entity”错误,这意味着Hibernate并未识别到该实体类。 解决方案:确保实体类已添加@Entity注解,并且该类所在的包已被配置在...

    hibernate常见异常

    本文将介绍 Hibernate 中的一些常见异常,包括 net.sf.hibernate.MappingException、net.sf.hibernate.PropertyNotFoundException、org.hibernate.id.IdentifierGenerationException 以及 a different object with ...

    Hibernate映射导致的几个异常

    标题与描述概述的知识点主要集中在Hibernate映射过程中可能遇到的各种异常情况,这涉及到数据库与对象模型之间的映射问题,以及Hibernate框架在处理这些映射时可能产生的错误。下面将对这些异常进行详细的解释和分析...

    hibernate常见问题及处理.doc

    4. `org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():` 此异常意味着在尝试保存对象前,对象的主键没有被正确设置。通常,这是由于在映射...

    JPA 开发中遇到的错误

    org.hibernate.MappingException: Unable to find column with logical name 这表示Hibernate在构建映射时未能找到与实体属性相对应的数据库列。确保实体类中的属性名称与数据库表中的列名相匹配,或者使用`@...

    org.dozer JAR 包(实现java bean mapper)

    dozer是一款优秀的java bean映射开源框架,完成深度转换Bean&lt;-&gt;Bean的Mapper实现

    EmbeddableTypes

    ( org.hibernate.MappingException: Repeated column in mapping for entity:YOUR_ENTITY ),因为表databsae不能具有重复的列名。 JPA定义了@AttributeOverride批注来处理此senario。 @AttributeOverrides({ @...

    orika-sample:使用“ ma.glasnost.orika”的样本

    "orika-sample:使用“ma.glasnost.orika”的样本"是一个关于Java对象映射库Orika的实践项目。Orika是一个高性能、易用的对象映射框架,它简化了Java对象到Java对象之间的数据转换过程。这个项目提供了一系列示例,...

    最经典的hibernate教程_从入门到精通3(hbiernate学习)

    首先,让我们解决异常`org.hibernate.MappingException: Unknown entity: com.aptech.jb.entity.TblUser`。这个异常通常是因为Hibernate没有找到指定的实体映射文件。解决方法是在`Hibernate.cfg.xml`配置文件中添加...

    hibernate配置properties

    ### Hibernate配置Properties详解 在Java开发环境中,Hibernate作为一款优秀的对象关系映射(ORM)框架,为开发者提供了高效且简洁的方式来进行数据库操作。而在Hibernate的实际应用过程中,合理的配置显得尤为重要...

    hibernate教程从入门到精通第篇共四篇PPT学习教案.pptx

    在使用Hibernate时,可能会遇到`org.hibernate.MappingException: Unknown entity`这样的异常,这通常是因为在配置文件(如Hibernate.cfg.xml)中未指定实体的映射文件。例如,如果实体类为`...

    hibernate常见错误解决方案

    ### Hibernate常见错误解决方案 在开发基于Hibernate框架的应用程序时,我们经常会遇到各种各样的异常情况。这些异常不仅会影响系统的正常运行,还可能增加调试难度。本文将针对几个常见的Hibernate异常进行详细...

    hibernate ppt

    首先,出现 `org.hibernate.MappingException: Unknown entity` 异常通常是因为 Hibernate 没有找到指定的实体映射文件。在本例中,错误提示说没有在 Hibernate.cfg.xml 文件中添加 `&lt;mapping&gt;` 元素来指明 `...

    eclipse反向差件

    - **异常示例**:`org.hibernate.MappingException: Could not configure overrides from file`。 - **解决方法**:这通常是由于生成的`hibernate.reveng.xml`文件格式不正确导致的。解决方法是修改该文件的头部...

    hibernate核心,一对多,多对多映射讲解,看了就完全搞明白了

    `MappingException: Unknown entity` 异常通常意味着Hibernate无法识别或找不到指定的实体类。在本例中,问题在于Hibernate配置文件`Hibernate.cfg.xml`中没有包含`TblUser`实体的映射信息。要解决这个问题,你需要...

    Hibernate入门

    首先,我们来看一下在使用Hibernate时遇到的一个典型问题,即`MappingException: Unknown entity`异常。这个异常通常表示Hibernate无法找到指定的实体映射。在给定的代码片段中,问题出在没有在`Hibernate.cfg.xml`...

Global site tag (gtag.js) - Google Analytics