-->
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: Trouble with @TableGenerator : "...no natively generate
PostPosted: Sat Dec 02, 2006 6:26 am 
Beginner
Beginner

Joined: Thu Feb 17, 2005 6:04 pm
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.1

Mapping documents:

<persistence-unit name="primary" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>qnext.bo.dao.entities.PublicZone</class>
<class>qnext.bo.dao.entities.MailContent</class>
<class>qnext.bo.dao.entities.Machine</class>
<class>qnext.bo.dao.entities.JarService</class>
<class>qnext.bo.dao.entities.DownloadServer</class>
<class>qnext.bo.dao.entities.StatLog</class>
<class>qnext.bo.dao.entities.BoRole</class>
<class>qnext.bo.dao.entities.AppConfig</class>
<class>qnext.bo.dao.entities.CampaignCondField</class>
<class>qnext.bo.dao.entities.GeoCity</class>
<class>qnext.bo.dao.entities.JarOs</class>
<class>qnext.bo.dao.entities.Stat</class>
<class>qnext.bo.dao.entities.Jar</class>
<class>qnext.bo.dao.entities.Url</class>
<class>qnext.bo.dao.entities.Contact</class>
<class>qnext.bo.dao.entities.Banner</class>
<class>qnext.bo.dao.entities.GeoCountryIp</class>
<class>qnext.bo.dao.entities.JarUser</class>
<class>qnext.bo.dao.entities.JarOem</class>
<class>qnext.bo.dao.entities.GeoCountry</class>
<class>qnext.bo.dao.entities.CampaignCond</class>
<class>qnext.bo.dao.entities.CampaignCondOp</class>
<class>qnext.bo.dao.entities.MailTrigger</class>
<class>qnext.bo.dao.entities.BoJarLog</class>
<class>qnext.bo.dao.entities.CampaignBanner</class>
<class>qnext.bo.dao.entities.Oem</class>
<class>qnext.bo.dao.entities.App</class>
<class>qnext.bo.dao.entities.UserDetail</class>
<class>qnext.bo.dao.entities.User</class>
<class>qnext.bo.dao.entities.TaskOwnership</class>
<class>qnext.bo.dao.entities.CampaignCondSet</class>
<class>qnext.bo.dao.entities.JarCrc</class>
<class>qnext.bo.dao.entities.Campaign</class>
<class>qnext.bo.dao.entities.BoUser</class>
<class>qnext.bo.dao.entities.GeoCityIp</class>
<class>qnext.bo.dao.entities.ConnectLevelOut</class>
<class>qnext.bo.dao.entities.ConnectLevelIn</class>
<class>qnext.bo.dao.entities.ContactType</class>
<class>qnext.bo.dao.entities.PrimType</class>
<class>qnext.bo.dao.entities.ServerStatus</class>
<class>qnext.bo.dao.entities.Os</class>
<class>qnext.bo.dao.entities.Invitation</class>
<class>qnext.bo.dao.entities.UserValue</class>
<class>qnext.bo.dao.entities.WebSession</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://192.168.1.40:3306/redirect_test"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="yeahright"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.c3p0.min_size" value="1"/>
<property name="hibernate.c3p0.max_size" value="1"/>
<property name="hibernate.c3p0.max_statements" value="10"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
</properties>
</persistence-unit>


Code between sessionFactory.openSession() and session.close():
None

Name and version of the database you are using:
Mysql 5.0 InnoDB table

I'm getting an exception reported by hibernate entity manager when I try to persist a new entity/row using table generation for the ID. I'm coming from toplink JPA, where this worked as I expected. I'm porting to hibernate entity manager, and I'm stumped on this one.

I persist as follows:

log.trace("persisting new entity : " + entity.toString());
em.persist(entity);
log.debug("persisted new entity : " + entity.toString());

Of course this is surrounted by transaction tags (I'm in a plain servlet without JTA).

I have the dialect set to : org.hibernate.dialect.MySQLInnoDBDialect. I tried the plain MySQL dialect as well.

Here is the exception.. It happens for basically all my tables, since they all use table generation.

1) testPersist(qnext.bo.dao.ops.BannerDaoTest)qnext.bo.redirect.InfraException: org.hibernate.HibernateException: The database returned no natively generated identity value
at qnext.bo.dao.jpa.GenericJpaDao.persist(GenericJpaDao.java:631)
at qnext.bo.dao.ops.BannerDaoTest.testPersist(BannerDaoTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
at qnext.bo.dao.jpa.GenericJpaDao.persist(GenericJpaDao.java:622)
... 16 more
Caused by: org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:33)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:74)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2108)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2588)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
... 17 more


Thanks,

Mal.


Top
 Profile  
 
 Post subject: Re: Trouble with @TableGenerator : "...no natively gene
PostPosted: Sat Dec 02, 2006 6:41 am 
Beginner
Beginner

Joined: Thu Feb 17, 2005 6:04 pm
Posts: 23
Found the solution just after posting which is inevitably the time it happens. First of all toplink doesn't mind, but hibernate wants this part which I omitted from my entity annotation:

@TableGenerator(name="banner_gen", table="id_generator", pkColumnName="table_name", valueColumnName="id_block", pkColumnValue="banner",allocationSize=50)
@Id @GeneratedValue(strategy=GenerationType.TABLE, generator="banner_gen")
@Column(name = "banner_id", nullable = false)
private Integer bannerId;

I had omitted the "strategy=GenerationType.TABLE". Toplink sees the TableGenerator tag and "generator="banner_gen" and deduces the strategy, but hibernate does not.

Then I had a strange problem when it would JAM when getting the new key. That was because I had my max connection pool set to 1 for performance during debug. Oops.

Hope this helps someone.

Mal.


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.