-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: errror(database returned no nativly genrated identity val)
PostPosted: Mon Dec 11, 2006 4:53 am 
Newbie

Joined: Fri Dec 08, 2006 2:05 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 8:45 am 
Newbie

Joined: Wed Sep 27, 2006 3:30 am
Posts: 7
Location: romania
probably your database is configured not to support identity columns so no id is generated when you save your object. Use a "native" generator instead of this "identity" one because it ensures platform independence.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.