Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Mapping documents:
hibernate.cfg.xml
<?xml version='1.0' encoding='windows-1252'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<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:///test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">guruji</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Employee.hbm.xml
<?xml version='1.0' encoding='windows-1252'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="view.Employee" table="EMPLOYEE">
<id name="id" column="EMP_ID" type="java.lang.Long" unsaved-value="3">
<generator class="identity"/>
</id>
<property name="name" column="EMP_NAME" type="java.lang.String" />
<property name="sal" column="SAL" type="java.lang.Double" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Employee emp = new Employee();
emp.setName("Mascon");
emp.setSal(25.98);
Full stack trace of any exception that occurs:
org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:33)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1774)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2192)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:238)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:428)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
at view.Hiber1.main(Hiber1.java:30)
Process exited with exit code 0.
Name and version of the database you are using:
MY-SQL-4.1.21
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html