[Texo/Hibernate] TransientObjectException: object references an unsaved transient instance [message #698694] |
Tue, 19 July 2011 21:55  |
Eclipse User |
|
|
|
I'm getting a org.hibernate.TransientObjectException exception when persisting data using Texo generated Hibernate classes:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: xxx.model.Agent
#0: org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
#1: org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
#2: org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:265)
#3: org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:275)
#4: org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:295)
#5: org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3403)
#6: org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:520)
#7: org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:230)
#8: org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
#9: org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
#10: org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
#11: org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
#12: org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
#13: org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
#14: org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
#15: xxx.db.ModelManagerPersist.endTransaction(ModelManagerPersist.java:103)
#16: xxx.asset.AssetManagerPersist.save(AssetManagerPersist.java:86)
This exception occurs when doing an endTransaction of a class called xxx.model.Asset which has many-to-one EReference to xxx.model.Agent. I have numerous other similar references in the Asset EClass which likely will have a similar exception problem, but this is the first one which hibernate hits.
I think this is a cascade issue, but the orm.xml generated by Texo seems to set cascade options:
<orm:many-to-one name="agent" optional="true" target-entity="xxx.model.Agent">
<orm:join-column/>
<orm:cascade>
<orm:cascade-persist/>
<orm:cascade-merge/>
<orm:cascade-refresh/>
</orm:cascade>
</orm:many-to-one>
All the transaction code worked fine using Teneo. I'm guessing it was doing a lot more heavy lifting under the covers than I knew.
Do I need to manually code a transaction to save each EReference EClass prior to saving the parent EClass?
|
|
|
|
|
|
|
Re: [Texo/Hibernate] TransientObjectException: object references an unsaved transient instance [message #699671 is a reply to message #699592] |
Fri, 22 July 2011 00:12   |
Eclipse User |
|
|
|
Hi Mike,
I don't think it is a specific Texo problem (cascades have different meanings and there are pros/cons to different
settings in different situations). But maybe the mapping can be generated in such a way that this problem does not occur
directly, although afaics the orm.xml is fine.
Is this something I can easily try myself? If you can send me a zipped project directly by email with a testcase I can
run then I can try to reproduce this.
There is lots of info on jpa/orm on the internet. The spec is quite readable, specifically the part where the
annotations are explained, chapters 11 and 12 (see attached):
http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html
gr. Martin
On 07/21/2011 11:18 PM, Mike Cooper wrote:
> Thanks Martin. I've traced the problem down to this:
>
> Class: AbstractEntityTuplizer
>
>
> public Serializable getIdentifier(Object entity, SessionImplementor session) {
> final Object id;
> if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
> id = entity;
> }
> else {
> if ( idGetter == null ) {
> if (identifierMapperType==null) {
> throw new HibernateException( "The class has no identifier property: " + getEntityName() );
> }
> else {
> id = mappedIdentifierValueMarshaller.getIdentifier( entity, getEntityMode(), session );
> }
> }
> else {
> id = idGetter.get( entity );
> }
> }
>
> try {
> /* RETURNS null => */ return (Serializable) id;
> }
>
>
> The "id" var is returned as null. Back up the stack this causes hibernate to mark the class as transient.
>
> I'm definitely out of my depth at this point and not sure how to proceed. Do you think this is related to the texo
> generated orm.xml or some other texo generated file? Or is this likely to be something in my code or hibernate itself?
> What's a good reference doc for the orm.xml syntax? Maybe I can dig around there.
>
> mike
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
Re: [Texo/Hibernate] TransientObjectException: object references an unsaved transient instance [message #700119 is a reply to message #700032] |
Fri, 22 July 2011 16:42  |
Eclipse User |
|
|
|
Yes please do enter a bugzilla, I am surprised as persist, merge and refresh are the most common one, the other ones
(remove, refresh, detach) make less sense.If you enter a bugzilla then I will add refresh and detach, remove just does
not make sense for most many-to-ones...
gr. Martin
On 07/22/2011 08:29 PM, Mike Cooper wrote:
> I have it working now. If I manually edit orm.xml and replace all of the <orm:cascade-.../> entries with
> <orm:cascade-all/> it works fine. Looking back at how my code used Teneo prior to Texo I also set "cascade=all" so it
> makes sense now.
>
> So how do I get Texo to use cascade-all instead of cascade-merge, etc? Should I file an enhencement/bug in bugzilla?
>
> Cheers,
> mike
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Powered by
FUDForum. Page generated in 0.04877 seconds