Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Teneo: HibernateException when trying to save HibernateResource
|
Re: Teneo: HibernateException when trying to save HibernateResource [message #54473 is a reply to message #54446] |
Fri, 29 September 2006 11:00 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Hans,
Each HibernateResource has its own session. When you save one resource the references are followed
and the objects in the second resource are saved also using the session of the first resource. This
results in an error.
So basically working with references between multiple hibernateresources is not yet supported.
The solution would be to move session and transaction control also outside of the resource (to the
resourceset). This has not been implemented yet (adding a feature request in bugzilla can help).
What you can try for now is load all the data in one resource using multiple queries. You can
specify multiple queries in the url by using parameters query1, query2, query3, etc.
gr. Martin
Hans Mueller-Dieckert wrote:
> Hi,
>
> I have two HibernateResources with the contents of each Resource being
> build by a query.
>
> When i set a Reference from an object contained in Resource A to an
> object contained in Resource B, trying to save Resource A results in an
> HibernateException with the message "Illegal attempt to associate a
> collection with two open sessions".
>
> Am I missing some option or is this a bug or a not supported feature ?
>
> I've attached the full stack trace and an class diagram showing my test
> model. The classes named First* are contained in Resource A while the
> classes named Second* are contained in Resource B.
>
> If it would be helpful, I can also supply my test-plugin containing the
> EMF model and a junit test case as well.
>
> greetings,
> Hans
>
>
> ------------------------------------------------------------ ------------
>
> org.eclipse.emf.teneo.hibernate.HbStoreException: Exception when saving resource test
> at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:214)
> at org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:271)
> at de.arcsolutions.remarc.platform.emftest.TwoResourcesLinkTest Case.testTwoResources(TwoResourcesLinkTestCase.java:77)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
> at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:58)
> at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:24)
> at org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
> at org.eclipse.core.launcher.Main.run(Main.java:977)
> at org.eclipse.core.launcher.Main.main(Main.java:952)
> Caused by: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
> at org.hibernate.collection.AbstractPersistentCollection.setCur rentSession(AbstractPersistentCollection.java:410)
> at org.hibernate.event.def.OnUpdateVisitor.processCollection(On UpdateVisitor.java:40)
> at org.hibernate.event.def.AbstractVisitor.processValue(Abstrac tVisitor.java:101)
> at org.hibernate.event.def.AbstractVisitor.processValue(Abstrac tVisitor.java:61)
> at org.hibernate.event.def.AbstractVisitor.processEntityPropert yValues(AbstractVisitor.java:55)
> at org.hibernate.event.def.AbstractVisitor.process(AbstractVisi tor.java:123)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formUpdate(DefaultSaveOrUpdateEventListener.java:267)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
> at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:502)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :494)
> at org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:134)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :157)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:10 8)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:223)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cas cadeOnUpdate(DefaultSaveOrUpdateEventListener.java:331)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formUpdate(DefaultSaveOrUpdateEventListener.java:303)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
> at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:502)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :494)
> at org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:134)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :157)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:10 8)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
> at org.hibernate.event.def.AbstractFlushingEventListener.cascad eOnFlush(AbstractFlushingEventListener.java:130)
> at org.hibernate.event.def.AbstractFlushingEventListener.prepar eEntityFlushes(AbstractFlushingEventListener.java:121)
> at org.hibernate.event.def.AbstractFlushingEventListener.flushE verythingToExecutions(AbstractFlushingEventListener.java:65)
> at org.hibernate.event.def.DefaultFlushEventListener.onFlush(De faultFlushEventListener.java:26)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
> at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:210)
> ... 34 more
>
>
>
> ------------------------------------------------------------ ------------
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: HibernateException when trying to save HibernateResource [message #55924 is a reply to message #54473] |
Mon, 02 October 2006 22:09 |
Eclipse User |
|
|
|
Originally posted by: sprakash.tibco.com
Hi Martin,
I have the same problem. But I notice that HibernateResource.unload()
doesnt actually close the underlying Hibernate session (unless I am
looking at the wrong code again). Why is that? So the Hibernate sessions
are cleaned only through garbage collection then? My problem is that if I
retrieve Object A from Resource 1 and then unload Resource 1, I was
expecting that Object A would become a detached object (in Hibernate
terminology). Next when I retrieve Object B in Resource 2 and add Object A
to resource 2, I get the same exception "Illegal ..." when I save Resource
2, because Object A and its collection are still persistent objects of the
session in Resource 1. If HibernateResource.unload() actually closed the
session, wouldnt everything automatically be ok? If so, why doesnt
HibernateResource.unload() actually close the session, only set it to null?
Thanks in advance,
Sundeep
|
|
|
Re: Teneo: HibernateException when trying to save HibernateResource [message #56026 is a reply to message #55924] |
Tue, 03 October 2006 05:55 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Sundeep,
I think there are two issues which you mention here:
1) closing the session when unloading. This is a missing feature (or oversight from me). Can you
enter a bugzilla for this? I use bugzilla to keep a public record of changes that's why I prefer a
bugzilla entry for also smaller things to add (like this).
2) having multiple resources with objects refering to eachother. This I will solve in the next
release. My idea is to add the concept of a sessioncontroller which is registered by name, the
session controller can then be used by multiple resources sharing one session. The transaction
handling then needs to be done outside of the actual resource save action.
gr. Martin
Sundeep Prakash wrote:
> Hi Martin,
> I have the same problem. But I notice that HibernateResource.unload()
> doesnt actually close the underlying Hibernate session (unless I am
> looking at the wrong code again). Why is that? So the Hibernate sessions
> are cleaned only through garbage collection then? My problem is that if
> I retrieve Object A from Resource 1 and then unload Resource 1, I was
> expecting that Object A would become a detached object (in Hibernate
> terminology). Next when I retrieve Object B in Resource 2 and add Object
> A to resource 2, I get the same exception "Illegal ..." when I save
> Resource 2, because Object A and its collection are still persistent
> objects of the session in Resource 1. If HibernateResource.unload()
> actually closed the session, wouldnt everything automatically be ok? If
> so, why doesnt HibernateResource.unload() actually close the session,
> only set it to null?
>
> Thanks in advance,
>
> Sundeep
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: HibernateException when trying to save HibernateResource [message #592694 is a reply to message #54446] |
Fri, 29 September 2006 11:00 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Hans,
Each HibernateResource has its own session. When you save one resource the references are followed
and the objects in the second resource are saved also using the session of the first resource. This
results in an error.
So basically working with references between multiple hibernateresources is not yet supported.
The solution would be to move session and transaction control also outside of the resource (to the
resourceset). This has not been implemented yet (adding a feature request in bugzilla can help).
What you can try for now is load all the data in one resource using multiple queries. You can
specify multiple queries in the url by using parameters query1, query2, query3, etc.
gr. Martin
Hans Mueller-Dieckert wrote:
> Hi,
>
> I have two HibernateResources with the contents of each Resource being
> build by a query.
>
> When i set a Reference from an object contained in Resource A to an
> object contained in Resource B, trying to save Resource A results in an
> HibernateException with the message "Illegal attempt to associate a
> collection with two open sessions".
>
> Am I missing some option or is this a bug or a not supported feature ?
>
> I've attached the full stack trace and an class diagram showing my test
> model. The classes named First* are contained in Resource A while the
> classes named Second* are contained in Resource B.
>
> If it would be helpful, I can also supply my test-plugin containing the
> EMF model and a junit test case as well.
>
> greetings,
> Hans
>
>
> ------------------------------------------------------------ ------------
>
> org.eclipse.emf.teneo.hibernate.HbStoreException: Exception when saving resource test
> at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:214)
> at org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:271)
> at de.arcsolutions.remarc.platform.emftest.TwoResourcesLinkTest Case.testTwoResources(TwoResourcesLinkTestCase.java:77)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
> at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:58)
> at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:24)
> at org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
> at org.eclipse.core.launcher.Main.run(Main.java:977)
> at org.eclipse.core.launcher.Main.main(Main.java:952)
> Caused by: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
> at org.hibernate.collection.AbstractPersistentCollection.setCur rentSession(AbstractPersistentCollection.java:410)
> at org.hibernate.event.def.OnUpdateVisitor.processCollection(On UpdateVisitor.java:40)
> at org.hibernate.event.def.AbstractVisitor.processValue(Abstrac tVisitor.java:101)
> at org.hibernate.event.def.AbstractVisitor.processValue(Abstrac tVisitor.java:61)
> at org.hibernate.event.def.AbstractVisitor.processEntityPropert yValues(AbstractVisitor.java:55)
> at org.hibernate.event.def.AbstractVisitor.process(AbstractVisi tor.java:123)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formUpdate(DefaultSaveOrUpdateEventListener.java:267)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
> at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:502)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :494)
> at org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:134)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :157)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:10 8)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:223)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cas cadeOnUpdate(DefaultSaveOrUpdateEventListener.java:331)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formUpdate(DefaultSaveOrUpdateEventListener.java:303)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
> at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:502)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :494)
> at org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:134)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :157)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:10 8)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
> at org.hibernate.event.def.AbstractFlushingEventListener.cascad eOnFlush(AbstractFlushingEventListener.java:130)
> at org.hibernate.event.def.AbstractFlushingEventListener.prepar eEntityFlushes(AbstractFlushingEventListener.java:121)
> at org.hibernate.event.def.AbstractFlushingEventListener.flushE verythingToExecutions(AbstractFlushingEventListener.java:65)
> at org.hibernate.event.def.DefaultFlushEventListener.onFlush(De faultFlushEventListener.java:26)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
> at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:210)
> ... 34 more
>
>
>
> ------------------------------------------------------------ ------------
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: HibernateException when trying to save HibernateResource [message #593383 is a reply to message #55924] |
Tue, 03 October 2006 05:55 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Sundeep,
I think there are two issues which you mention here:
1) closing the session when unloading. This is a missing feature (or oversight from me). Can you
enter a bugzilla for this? I use bugzilla to keep a public record of changes that's why I prefer a
bugzilla entry for also smaller things to add (like this).
2) having multiple resources with objects refering to eachother. This I will solve in the next
release. My idea is to add the concept of a sessioncontroller which is registered by name, the
session controller can then be used by multiple resources sharing one session. The transaction
handling then needs to be done outside of the actual resource save action.
gr. Martin
Sundeep Prakash wrote:
> Hi Martin,
> I have the same problem. But I notice that HibernateResource.unload()
> doesnt actually close the underlying Hibernate session (unless I am
> looking at the wrong code again). Why is that? So the Hibernate sessions
> are cleaned only through garbage collection then? My problem is that if
> I retrieve Object A from Resource 1 and then unload Resource 1, I was
> expecting that Object A would become a detached object (in Hibernate
> terminology). Next when I retrieve Object B in Resource 2 and add Object
> A to resource 2, I get the same exception "Illegal ..." when I save
> Resource 2, because Object A and its collection are still persistent
> objects of the session in Resource 1. If HibernateResource.unload()
> actually closed the session, wouldnt everything automatically be ok? If
> so, why doesnt HibernateResource.unload() actually close the session,
> only set it to null?
>
> Thanks in advance,
>
> Sundeep
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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
|
|
| | |
Goto Forum:
Current Time: Sat Nov 09 05:24:17 GMT 2024
Powered by FUDForum. Page generated in 0.03812 seconds
|