Joined: Sun Sep 22, 2013 12:28 am Posts: 1
|
My code is given below:
package main.java;
import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration;
public class EmployeeDetails {
/** * @param args */ public static void main(String[] args) { Employee employee = new Employee(); employee.setEmployeeId(1); employee.setEmployeeName("First Employee"); SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction(); session.save(employee); session.getTransaction().commit(); session.close(); }
}
//This is my pojo
package main.java;
public class Employee {
private int employeeId; private String employeeName; public int getEmployeeId() { return employeeId; } public void setEmployeeId(int employeeId) { this.employeeId = employeeId; } public String getEmployeeName() { return employeeName; } public void setEmployeeName(String employeeName) { this.employeeName = employeeName; } }
//This is my hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/test</property> <property name="connection.username">****</property> <property name="connection.password">********</property>
<!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property>
<!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property>
<!--Names the annotated entity class --> <mapping class = "main.java.Employee" /> </session-factory>
</hibernate-configuration>
when i am trying to run this code i am getting the following error:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: main.java.Employee at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1141) at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1433) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:116) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206) at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191) 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:764) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:756) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:752) at main.java.EmployeeDetails.main(EmployeeDetails.java:20)
can Any on eplease help me solve this error?
THanks in advance, hibnatePassion
|
|