Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Cascading dilemma.
[Teneo] Cascading dilemma. [message #645460] Fri, 17 December 2010 09:56 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

I have two requirements which force me to have different cascading
policies. It seems, I would need different cascading options as
concurring actions can't co-exist (At least this is what I seem to
experience). Is there a way to do this without initializing the
datastore? (On the fly?).

The two cases are:

1. Moving objects in a tree (Using a Hibernate Resource)-> Requires the
casding policy to be
props.setProperty(PersistenceOptions.SET_CASCADE_ALL_ON_CONT AINMENT,
"false");

(Moving would throw a Hibernate exception).

2. Saving the complete content of an EObject root to Hibernate, which
will throw an exception with the above option on. (I previously asked
about this, and the following option was advised:

props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTA INMENT,
"ALL");

10:51:45,174 ERROR AbstractFlushingEventListener:324 - Could not
synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved
transient instance - save the transient instance before flushing: Equipment
at
org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUns aved(ForeignKeys.java:242)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java: 430)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.j ava:101)
at
org.hibernate.persister.collection.AbstractCollectionPersist er.writeElement(AbstractCollectionPersister.java:777)
at
org.hibernate.persister.collection.AbstractCollectionPersist er.recreate(AbstractCollectionPersister.java:1165)
at
org.hibernate.action.CollectionRecreateAction.execute(Collec tionRecreateAction.java:58)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)


Here is the code:

// Make a copy.
EcoreUtil.Copier copier = new EcoreUtil.Copier();
EObject copy = copier.copy(root);
copier.copyReferences();

Session session = TeneoService.getInstance().getSession();
Transaction tx = session.beginTransaction();

// Save our new copy.
session.save(copy);

try {
tx.commit();

} catch (Exception e) {
if (tx != null)
tx.rollback();
return null;
}
Re: [Teneo] Cascading dilemma. [message #645735 is a reply to message #645460] Mon, 20 December 2010 10:02 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Christophe,
The reason that the copy-paste does not work is because of the delete-orphan cascading setting. I think you saw this
part of the wiki already:
http://wiki.eclipse.org/Teneo/Hibernate/EMF_Hibernate_Integr ation_Details#Move_an_EObject_between_EContainers_or_support _cut_and_paste_in_the_EMF_editor

I think to solve this issue you have to set this option:
teneo.mapping.cascade_policy_on_containment
to:
REMOVE, REFRESH, PERSIST, MERGE

You can also set default cascade options for non-containment associations, see this page:
http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Option s

gr. Martin

On 12/17/2010 10:56 AM, Christophe Bouhier wrote:
> Hi,
>
> I have two requirements which force me to have different cascading policies. It seems, I would need different cascading
> options as concurring actions can't co-exist (At least this is what I seem to experience). Is there a way to do this
> without initializing the datastore? (On the fly?).
>
> The two cases are:
>
> 1. Moving objects in a tree (Using a Hibernate Resource)-> Requires the casding policy to be
> props.setProperty(PersistenceOptions.SET_CASCADE_ALL_ON_CONT AINMENT, "false");
>
> (Moving would throw a Hibernate exception).
>
> 2. Saving the complete content of an EObject root to Hibernate, which will throw an exception with the above option on.
> (I previously asked about this, and the following option was advised:
>
> props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTA INMENT,
> "ALL");
>
> 10:51:45,174 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
> org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance
> before flushing: Equipment
> at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUns aved(ForeignKeys.java:242)
> at org.hibernate.type.EntityType.getIdentifier(EntityType.java: 430)
> at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.j ava:101)
> at org.hibernate.persister.collection.AbstractCollectionPersist er.writeElement(AbstractCollectionPersister.java:777)
> at org.hibernate.persister.collection.AbstractCollectionPersist er.recreate(AbstractCollectionPersister.java:1165)
> at org.hibernate.action.CollectionRecreateAction.execute(Collec tionRecreateAction.java:58)
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
>
>
> Here is the code:
>
> // Make a copy.
> EcoreUtil.Copier copier = new EcoreUtil.Copier();
> EObject copy = copier.copy(root);
> copier.copyReferences();
>
> Session session = TeneoService.getInstance().getSession();
> Transaction tx = session.beginTransaction();
>
> // Save our new copy.
> session.save(copy);
>
> try {
> tx.commit();
>
> } catch (Exception e) {
> if (tx != null)
> tx.rollback();
> return null;
> }


--

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: [Teneo] Cascading dilemma. [message #645908 is a reply to message #645735] Tue, 21 December 2010 06:31 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Thanks Martin,
This seems to solve the issue.
Cheers Christophe

On 20-12-10 11:02, Martin Taal wrote:
> Hi Christophe,
> The reason that the copy-paste does not work is because of the
> delete-orphan cascading setting. I think you saw this part of the wiki
> already:
> http://wiki.eclipse.org/Teneo/Hibernate/EMF_Hibernate_Integr ation_Details#Move_an_EObject_between_EContainers_or_support _cut_and_paste_in_the_EMF_editor
>
>
> I think to solve this issue you have to set this option:
> teneo.mapping.cascade_policy_on_containment
> to:
> REMOVE, REFRESH, PERSIST, MERGE
>
> You can also set default cascade options for non-containment
> associations, see this page:
> http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Option s
>
> gr. Martin
>
> On 12/17/2010 10:56 AM, Christophe Bouhier wrote:
>> Hi,
>>
>> I have two requirements which force me to have different cascading
>> policies. It seems, I would need different cascading
>> options as concurring actions can't co-exist (At least this is what I
>> seem to experience). Is there a way to do this
>> without initializing the datastore? (On the fly?).
>>
>> The two cases are:
>>
>> 1. Moving objects in a tree (Using a Hibernate Resource)-> Requires
>> the casding policy to be
>> props.setProperty(PersistenceOptions.SET_CASCADE_ALL_ON_CONT AINMENT,
>> "false");
>>
>> (Moving would throw a Hibernate exception).
>>
>> 2. Saving the complete content of an EObject root to Hibernate, which
>> will throw an exception with the above option on.
>> (I previously asked about this, and the following option was advised:
>>
>> props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTA INMENT,
>> "ALL");
>>
>> 10:51:45,174 ERROR AbstractFlushingEventListener:324 - Could not
>> synchronize database state with session
>> org.hibernate.TransientObjectException: object references an unsaved
>> transient instance - save the transient instance
>> before flushing: Equipment
>> at
>> org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUns aved(ForeignKeys.java:242)
>>
>> at org.hibernate.type.EntityType.getIdentifier(EntityType.java: 430)
>> at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.j ava:101)
>> at
>> org.hibernate.persister.collection.AbstractCollectionPersist er.writeElement(AbstractCollectionPersister.java:777)
>>
>> at
>> org.hibernate.persister.collection.AbstractCollectionPersist er.recreate(AbstractCollectionPersister.java:1165)
>>
>> at
>> org.hibernate.action.CollectionRecreateAction.execute(Collec tionRecreateAction.java:58)
>>
>> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
>>
>>
>> Here is the code:
>>
>> // Make a copy.
>> EcoreUtil.Copier copier = new EcoreUtil.Copier();
>> EObject copy = copier.copy(root);
>> copier.copyReferences();
>>
>> Session session = TeneoService.getInstance().getSession();
>> Transaction tx = session.beginTransaction();
>>
>> // Save our new copy.
>> session.save(copy);
>>
>> try {
>> tx.commit();
>>
>> } catch (Exception e) {
>> if (tx != null)
>> tx.rollback();
>> return null;
>> }
>
>
Previous Topic:Resolve Proxy in Model
Next Topic:[CDO] using non-sql backend
Goto Forum:
  


Current Time: Thu Mar 28 19:24:47 GMT 2024

Powered by FUDForum. Page generated in 0.02072 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top