Jasper with Hibernate - 找不到实体类
Posted
技术标签:
【中文标题】Jasper with Hibernate - 找不到实体类【英文标题】:Jasper with Hibernate - entity class not found 【发布时间】:2013-09-20 15:19:15 【问题描述】:我正在尝试创建一个带有休眠连接的 jasper,如教程 http://www.tutorialcenters.com/index.php/how-to-design-report-using-jasperreport-hibernate-connection/
中所示我完全按照教程中的说明做了,但是当我得到
entity class not found: mappings.EmployeeMaster
谁能告诉我一些解决方案....
我在 netbeans IDE 中的 samplehiber 项目结构 - CLICK
设置类路径 - CLICK
使用休眠配置与 MySQL 数据库建立连接 - CLICK
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.mysqlDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hse</property>
<property name="hibernate.connection.username">root</property>
<mapping resource="mappings/EmployeeMaster.hbm.xml"/>
</session-factory>
</hibernate-configuration>
hibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="hse"/>
<table-filter match-name="employee_master"/>
</hibernate-reverse-engineering>
EmployeeMaster.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 15, 2013 11:07:05 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping >
<class name="mappings.EmployeeMaster" table="employee_master" catalog="hse">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="userCode" type="string">
<column name="user_code" length="60" not-null="true" unique="true" />
</property>
<property name="firstName" type="string">
<column name="first_name" length="60" />
</property>
<property name="lastName" type="string">
<column name="last_name" length="60" />
</property>
<property name="deptId" type="java.lang.Integer">
<column name="dept_id" />
</property>
<property name="designationId" type="java.lang.Integer">
<column name="designation_id" />
</property>
<property name="empEmail" type="string">
<column name="emp_email" length="60" />
</property>
<property name="status" type="string">
<column name="status" length="20" />
</property>
<property name="createdDate" type="timestamp">
<column name="created_date" length="19" />
</property>
<property name="modifiedDate" type="timestamp">
<column name="modified_date" length="19" />
</property>
</class>
</hibernate-mapping>
EmployeeMaster.java
package mappings;
import java.util.Date;
public class EmployeeMaster implements java.io.Serializable
private Integer id;
private String userCode;
private String firstName;
private String lastName;
private Integer deptId;
private Integer designationId;
private String empEmail;
private String status;
private Date createdDate;
private Date modifiedDate;
public EmployeeMaster()
public EmployeeMaster(String userCode)
this.userCode = userCode;
public EmployeeMaster(String userCode, String firstName, String lastName, Integer deptId, Integer designationId, String empEmail, String status, Date createdDate, Date modifiedDate)
this.userCode = userCode;
this.firstName = firstName;
this.lastName = lastName;
this.deptId = deptId;
this.designationId = designationId;
this.empEmail = empEmail;
this.status = status;
this.createdDate = createdDate;
this.modifiedDate = modifiedDate;
public Integer getId()
return this.id;
public void setId(Integer id)
this.id = id;
public String getUserCode()
return this.userCode;
public void setUserCode(String userCode)
this.userCode = userCode;
public String getFirstName()
return this.firstName;
public void setFirstName(String firstName)
this.firstName = firstName;
public String getLastName()
return this.lastName;
public void setLastName(String lastName)
this.lastName = lastName;
public Integer getDeptId()
return this.deptId;
public void setDeptId(Integer deptId)
this.deptId = deptId;
public Integer getDesignationId()
return this.designationId;
public void setDesignationId(Integer designationId)
this.designationId = designationId;
public String getEmpEmail()
return this.empEmail;
public void setEmpEmail(String empEmail)
this.empEmail = empEmail;
public String getStatus()
return this.status;
public void setStatus(String status)
this.status = status;
public Date getCreatedDate()
return this.createdDate;
public void setCreatedDate(Date createdDate)
this.createdDate = createdDate;
public Date getModifiedDate()
return this.modifiedDate;
public void setModifiedDate(Date modifiedDate)
this.modifiedDate = modifiedDate;
IDE 日志
org.hibernate.MappingException: entity class not found: mappings.EmployeeMaster
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:147)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at com.jaspersoft.ireport.designer.connection.JRHibernateConnection.getSessionFactory(JRHibernateConnection.java:130)
at com.jaspersoft.ireport.designer.connection.JRHibernateConnection$1.run(JRHibernateConnection.java:157)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:121)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1072)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1013)
at java.awt.Dialog.setVisible(Dialog.java:1003)
at com.jaspersoft.ireport.designer.connection.gui.ConnectionsDialog.jButtonNewParameterActionPerformed(ConnectionsDialog.java:578)
at com.jaspersoft.ireport.designer.connection.gui.ConnectionsDialog.access$400(ConnectionsDialog.java:47)
at com.jaspersoft.ireport.designer.connection.gui.ConnectionsDialog$7.actionPerformed(ConnectionsDialog.java:221)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:121)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1072)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1013)
at java.awt.Dialog.setVisible(Dialog.java:1003)
at com.jaspersoft.ireport.designer.connection.gui.ConnectionsDialog.setVisible(ConnectionsDialog.java:651)
at com.jaspersoft.ireport.designer.menu.DatasourcesAction.performAction(DatasourcesAction.java:46)
at org.openide.util.actions.CallableSystemAction$1.run(CallableSystemAction.java:118)
at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:77)
at org.openide.util.actions.CallableSystemAction.actionPerformed(CallableSystemAction.java:114)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at org.openide.awt.ToolbarButton.processMouseEvent(ToolbarButton.java:61)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassNotFoundException: mappings.EmployeeMaster
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:252)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:123)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:119)
... 123 more
【问题讨论】:
我可以看到您正在使用 mysql 数据库并希望通过休眠连接进行连接。用 mysql 连接你的数据库。 先生,但我的 jasper 报告中需要休眠连接...... 您使用的是哪个数据库? 我正在使用 mysql........ 然后用mysql而不是hibernate连接来连接你的数据库。试一次然后告诉我。 【参考方案1】:您将 Jasper 指向源文件。 Jasper 想要一个 jar 或类文件。在 Netbeans 中构建您的项目并观察 jar 位置的输出。
通常 Netbeans 将 jar 构建到项目的 dist 目录 (samplehiber/dist/samplehiber.jar)。这就是您需要在 Jasper 类路径中添加的内容。
如果您想使用类文件,请将 Jasper 指向您的 samplehiber/build/classes 目录。
【讨论】:
【参考方案2】:您的类路径中需要有一个 EmployeeMaster.class
文件。确保你重建你的项目。查看您的工具在哪里构建您的 .class
文件并将目录添加到您的类路径中。
【讨论】:
@user2040500 您的c:\Users\Work\Desktop\samplehiber\src\java\mappings
目录中有EmployeeMaster.class
文件吗?
@user2040500 你可以尝试从类路径中删除c:\Users\Work\Desktop\samplehiber\src\java\mappings
,只留下c:\Users\Work\Desktop\samplehiber\src\java
是的,我这样做了,但仍然是同样的错误......找不到实体类:mappings.EmployeeMaster
你需要在类路径中有一个 EmployeeMaster.class 文件【参考方案3】:
我尝试了与您过去所做的类似的方法。事实证明,无论出于何种原因,hibernate 都无法在包中看到自己的 xml 文件。
为了简单起见,您是否尝试过将 EmployeeMaster.hbm.xml 移动到源的根文件夹?即 .\src 或 .\src\java (不确定哪个在 netbeans 中)
它对我有用。但请注意我的问题发生在 eclipse 中,因此它可能适用于这个问题,也可能不适用于这个问题。不过值得一试。 “如果一切都失败了,请保持设置简单。”这就是我经常说的消除其他因素。 :)
【讨论】:
以上是关于Jasper with Hibernate - 找不到实体类的主要内容,如果未能解决你的问题,请参考以下文章
org.hibernate.ObjectNotFoundException: No row with the given identifier exists
Hibernate Validator with Hibernate Dynamic Models (No Entity Class)
Hibernate报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法(示例代码
hibernate中一种导致a different object with the same identifier value was already associated with the sess
@Where with @SecondaryTable 不适用于 Hibernate
spring 3.1 with hibernate 4 with spring security 3.1:如何确保包含所有依赖项以及要包含哪些标签?