Jasper with Hibernate - entity class not found

I am trying to create a jasper with a sleeping compound, as shown in the tutorial http://www.tutorialcenters.com/index.php/how-to-design-report-using-jasperreport-hibernate-connection/

I did exactly as instructed, but when I get entity class not found: mappings.EmployeeMaster

Can someone tell me some solution for this ....

my samplehiber project structure in netbeans IDE - CLICK

Classpath setup - CLICK

Setting classpath

Configure MySQL database connection using hibernate configuration - 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 Magazine

 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 
+6
source share
3 answers

You specify Jasper in the source files. Jasper wants to create a jar or class files. Create your project in Netbeans and see the output for the location of the bank.

Typically, Netbeans build a jar in the dist project directory (samplehiber / dist / samplehiber.jar). This is what you need to impose on the Jasper class path.

If you want to use class files, specify Jasper in the samplehiber / build / classes directory.

+4
source

Your class path should have EmployeeMaster.class . Make sure you rebuild the project. See where your tool creates your .class files and adds a directory to your class path.

+3
source

I tried a similar approach to what you have done in the past. It turns out that for some reason hibernate cannot see its own XML files inside packages.

If you just tried moving EmployeeMaster.hbm.xml to the root folder of your source? those. \ src or. \ src \ java (not quite sure what netbeans has)

It worked for me. But note that my problem occurred in eclipse so that it may or may not apply to this problem. However, it's worth it. "If all else fails, keep the setting simple." This is what I always say to eliminate other factors. :)

0
source

Source: https://habr.com/ru/post/953919/


All Articles