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来扫描这个包下面的类。问题解决!
相关推荐
NULL 博文链接:https://guoyinjian.iteye.com/blog/1259538
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持续集成工具可以集成Maven工具,并支持其项目的自动化构件,我们可以通过对其配置达到以Maven的形式将构件项目自动化管理起来的目的。
错误表现:尝试操作某个实体类时,出现“org.hibernate.MappingException: Unknown entity”错误,这意味着Hibernate并未识别到该实体类。 解决方案:确保实体类已添加@Entity注解,并且该类所在的包已被配置在...
本文将介绍 Hibernate 中的一些常见异常,包括 net.sf.hibernate.MappingException、net.sf.hibernate.PropertyNotFoundException、org.hibernate.id.IdentifierGenerationException 以及 a different object with ...
标题与描述概述的知识点主要集中在Hibernate映射过程中可能遇到的各种异常情况,这涉及到数据库与对象模型之间的映射问题,以及Hibernate框架在处理这些映射时可能产生的错误。下面将对这些异常进行详细的解释和分析...
4. `org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():` 此异常意味着在尝试保存对象前,对象的主键没有被正确设置。通常,这是由于在映射...
org.hibernate.MappingException: Unable to find column with logical name 这表示Hibernate在构建映射时未能找到与实体属性相对应的数据库列。确保实体类中的属性名称与数据库表中的列名相匹配,或者使用`@...
dozer是一款优秀的java bean映射开源框架,完成深度转换Bean<->Bean的Mapper实现
( org.hibernate.MappingException: Repeated column in mapping for entity:YOUR_ENTITY ),因为表databsae不能具有重复的列名。 JPA定义了@AttributeOverride批注来处理此senario。 @AttributeOverrides({ @...
"orika-sample:使用“ma.glasnost.orika”的样本"是一个关于Java对象映射库Orika的实践项目。Orika是一个高性能、易用的对象映射框架,它简化了Java对象到Java对象之间的数据转换过程。这个项目提供了一系列示例,...
首先,让我们解决异常`org.hibernate.MappingException: Unknown entity: com.aptech.jb.entity.TblUser`。这个异常通常是因为Hibernate没有找到指定的实体映射文件。解决方法是在`Hibernate.cfg.xml`配置文件中添加...
### Hibernate配置Properties详解 在Java开发环境中,Hibernate作为一款优秀的对象关系映射(ORM)框架,为开发者提供了高效且简洁的方式来进行数据库操作。而在Hibernate的实际应用过程中,合理的配置显得尤为重要...
在使用Hibernate时,可能会遇到`org.hibernate.MappingException: Unknown entity`这样的异常,这通常是因为在配置文件(如Hibernate.cfg.xml)中未指定实体的映射文件。例如,如果实体类为`...
### Hibernate常见错误解决方案 在开发基于Hibernate框架的应用程序时,我们经常会遇到各种各样的异常情况。这些异常不仅会影响系统的正常运行,还可能增加调试难度。本文将针对几个常见的Hibernate异常进行详细...
首先,出现 `org.hibernate.MappingException: Unknown entity` 异常通常是因为 Hibernate 没有找到指定的实体映射文件。在本例中,错误提示说没有在 Hibernate.cfg.xml 文件中添加 `<mapping>` 元素来指明 `...
- **异常示例**:`org.hibernate.MappingException: Could not configure overrides from file`。 - **解决方法**:这通常是由于生成的`hibernate.reveng.xml`文件格式不正确导致的。解决方法是修改该文件的头部...
`MappingException: Unknown entity` 异常通常意味着Hibernate无法识别或找不到指定的实体类。在本例中,问题在于Hibernate配置文件`Hibernate.cfg.xml`中没有包含`TblUser`实体的映射信息。要解决这个问题,你需要...
首先,我们来看一下在使用Hibernate时遇到的一个典型问题,即`MappingException: Unknown entity`异常。这个异常通常表示Hibernate无法找到指定的实体映射。在给定的代码片段中,问题出在没有在`Hibernate.cfg.xml`...