Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [TENEO] Hibernate update exception when updating existing data
[TENEO] Hibernate update exception when updating existing data [message #86518] Fri, 15 June 2007 09:08 Go to next message
Duncan Alexander is currently offline Duncan AlexanderFriend
Messages: 90
Registered: July 2009
Member
Hi,
I have an EMF model which I have persisted into a DB using Teneo and Hibernate. My EMF model is
initially loaded from an XML document and calling save on the root of the object graph will
correctly persist the document into the DB.

In my application I am trying to deal with new xml documents which may contain new elements for
persisting or updates to existing elements which were persisted from previous XML document submissions.

Test 1:

As a basic test I have loaded an initial XML document into my EMF model then persisted this to the
DB. I then attempted to load exactly the same document and perform a session.update() passing in the
root of the object graph . Sounds reasonable, it should overlay the object values on top of the old
ones and increment the version of each persisted object in the DB.

Problem 1:

An exception is thrown of the form

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was
already associated with the session:
[cat.CategoryScheme#urn:sdmx:org.sdmx.infomodel.categorysche me.CategoryScheme=SDMX:categoryScheme1]

I am running this test in isolation so I have created a brand new session from Teneo, then I have
called empty() just to be sure, then when I perform my update( ) I see the error above. Am I missing
somethign here? How can the object possibly already be in the session ?

-----------

Test 2:

I load an initial XML document into my EMF model and persist this through Teneo/Hibernate to the DB.
I then attempt to load a new XML document which contains some new elements and one existing element.
I then call saveOrUpdate on the datagraph root. I would expect in this instance for hibernate to be
able to differentiate between new and existing elements and perform a save or update accordingly.

Problem 2:

An exception is thrown of the form

10:00:40,359 WARN JDBCExceptionReporter:77 - SQL Error: 1062, SQLState: 23000
10:00:40,359 ERROR JDBCExceptionReporter:78 - Duplicate entry
'urn:sdmx:org.sdmx.infomodel.base.Agency=SDMX' for key 1
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update....etc etc

It seems again that hibernate is not differentiating between existing and new objects but this time
it gets further and is attemtping to put the object into the DB, but with a save instead of an
update. Should Teneo/Hibernate be able to handle this mixture of new and existing elements.

-------------

Ive looked through the Hibernate forums extensively on this issue and I cant seem to find any exact
related issues. Im thinking that my problem is more to with EMF and Teneo and the semantics of how
they interact with Hibernate......but I could be on totally the wrong track.

Anyone ever tried anything similiar to the above .. ?

Any help is greatly appreciated as always.

Duncan
Re: [TENEO] Hibernate update exception when updating existing data [message #86535 is a reply to message #86518] Fri, 15 June 2007 11:44 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Duncan,
1) Hmm, what I can think of is the following: what can happen is that when saving part of the xml
tree an object from another part of the tree is loaded from the db (because there are references to
it), then when the other part of the tree is updated, hibernate finds that it already has an
instance with the same id.
2) I would need to run a testcase to get a better feel for what goes wrong there.

Can you make a small testcase for both cases?

gr. Martin

Duncan ALexander wrote:
> Hi,
> I have an EMF model which I have persisted into a DB using Teneo and
> Hibernate. My EMF model is initially loaded from an XML document and
> calling save on the root of the object graph will correctly persist the
> document into the DB.
>
> In my application I am trying to deal with new xml documents which may
> contain new elements for persisting or updates to existing elements
> which were persisted from previous XML document submissions.
>
> Test 1:
>
> As a basic test I have loaded an initial XML document into my EMF model
> then persisted this to the DB. I then attempted to load exactly the same
> document and perform a session.update() passing in the root of the
> object graph . Sounds reasonable, it should overlay the object values on
> top of the old ones and increment the version of each persisted object
> in the DB.
>
> Problem 1:
>
> An exception is thrown of the form
>
> org.hibernate.NonUniqueObjectException: a different object with the same
> identifier value was already associated with the session:
> [cat.CategoryScheme#urn:sdmx:org.sdmx.infomodel.categorysche me.CategoryScheme=SDMX:categoryScheme1]
>
>
> I am running this test in isolation so I have created a brand new
> session from Teneo, then I have called empty() just to be sure, then
> when I perform my update( ) I see the error above. Am I missing
> somethign here? How can the object possibly already be in the session ?
>
> -----------
>
> Test 2:
>
> I load an initial XML document into my EMF model and persist this
> through Teneo/Hibernate to the DB. I then attempt to load a new XML
> document which contains some new elements and one existing element. I
> then call saveOrUpdate on the datagraph root. I would expect in this
> instance for hibernate to be able to differentiate between new and
> existing elements and perform a save or update accordingly.
>
> Problem 2:
>
> An exception is thrown of the form
>
> 10:00:40,359 WARN JDBCExceptionReporter:77 - SQL Error: 1062, SQLState:
> 23000
> 10:00:40,359 ERROR JDBCExceptionReporter:78 - Duplicate entry
> 'urn:sdmx:org.sdmx.infomodel.base.Agency=SDMX' for key 1
> org.hibernate.exception.ConstraintViolationException: Could not execute
> JDBC batch update....etc etc
>
> It seems again that hibernate is not differentiating between existing
> and new objects but this time it gets further and is attemtping to put
> the object into the DB, but with a save instead of an update. Should
> Teneo/Hibernate be able to handle this mixture of new and existing
> elements.
>
> -------------
>
> Ive looked through the Hibernate forums extensively on this issue and I
> cant seem to find any exact related issues. Im thinking that my problem
> is more to with EMF and Teneo and the semantics of how they interact
> with Hibernate......but I could be on totally the wrong track.
>
> Anyone ever tried anything similiar to the above .. ?
>
> Any help is greatly appreciated as always.
>
> Duncan


--

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] Hibernate update exception when updating existing data [message #86550 is a reply to message #86535] Fri, 15 June 2007 12:11 Go to previous message
Duncan Alexander is currently offline Duncan AlexanderFriend
Messages: 90
Registered: July 2009
Member
Hi Martin,
I have a small test case but I have included my full set of ecore files and my full hibernate
mapping as Im not confident that I can detach subsections from them.

I have forwarded these directly to you as they are owned by a customer.

My test code would do the following (TeneoSessionManager handles the setup of the DBDataStore):

// LOAD AND SET THE INITIAL DB STATE
teneoSession = TeneoSessionManager.getInstance();
teneoSession.empty();
EDataGraph externalIMAsDatagraph =
StructureMother.INSTANCE.getExternalIMAsDatagraph(
"/resources/TEST_1.X_SDMXIM_REGISTRY_BASE.xml");
Session session = teneoSession.getSession();
Transaction transaction = session.getTransaction();
transaction.begin();
session.save(externalIMAsDatagraph.getERootObject());
session.flush();
transaction.commit();
session.close();

// ATTEMPT TO LOAD A FURTHER DOCUMENT AND UPDATE THE DB STATE
// BY SAVEORUPDATING EACH INDIVIDUAL ELEMENT IN THE DOCUMENT.
EDataGraph externalIMAsDatagraph =
StructureMother.INSTANCE.getExternalIMAsDatagraph(
"/resources/TEST_1.1_SDMXIM_DUPLICATE_CONCEPT_SCHEME.xml"); SDMXContainer sdmxContainer =
(SDMXContainer) externalIMAsDatagraph.getERootObject();
Session session = teneoSession.getSession();
Transaction transaction = session.getTransaction();
transaction.begin();
List identifiableList = sdmxContainer.getIdentifiable();
for (Object o : identifiableList) {
session.saveOrUpdate(o);
}
session.flush();
transaction.commit();
session.close();

-------------------------------------------------

From the above I would expect to see the Concept Scheme updated with one new concept (concept3) and
one updated concept(concept1) and one concept deleted (concept2)

Duncan



Martin Taal wrote:
> Hi Duncan,
> 1) Hmm, what I can think of is the following: what can happen is that
> when saving part of the xml tree an object from another part of the tree
> is loaded from the db (because there are references to it), then when
> the other part of the tree is updated, hibernate finds that it already
> has an instance with the same id.
> 2) I would need to run a testcase to get a better feel for what goes
> wrong there.
>
> Can you make a small testcase for both cases?
>
> gr. Martin
>
> Duncan ALexander wrote:
>> Hi,
>> I have an EMF model which I have persisted into a DB using Teneo
>> and Hibernate. My EMF model is initially loaded from an XML document
>> and calling save on the root of the object graph will correctly
>> persist the document into the DB.
>>
>> In my application I am trying to deal with new xml documents which may
>> contain new elements for persisting or updates to existing elements
>> which were persisted from previous XML document submissions.
>>
>> Test 1:
>>
>> As a basic test I have loaded an initial XML document into my EMF
>> model then persisted this to the DB. I then attempted to load exactly
>> the same document and perform a session.update() passing in the root
>> of the object graph . Sounds reasonable, it should overlay the object
>> values on top of the old ones and increment the version of each
>> persisted object in the DB.
>>
>> Problem 1:
>>
>> An exception is thrown of the form
>>
>> org.hibernate.NonUniqueObjectException: a different object with the
>> same identifier value was already associated with the session:
>> [cat.CategoryScheme#urn:sdmx:org.sdmx.infomodel.categorysche me.CategoryScheme=SDMX:categoryScheme1]
>>
>>
>> I am running this test in isolation so I have created a brand new
>> session from Teneo, then I have called empty() just to be sure, then
>> when I perform my update( ) I see the error above. Am I missing
>> somethign here? How can the object possibly already be in the session ?
>>
>> -----------
>>
>> Test 2:
>>
>> I load an initial XML document into my EMF model and persist this
>> through Teneo/Hibernate to the DB. I then attempt to load a new XML
>> document which contains some new elements and one existing element. I
>> then call saveOrUpdate on the datagraph root. I would expect in this
>> instance for hibernate to be able to differentiate between new and
>> existing elements and perform a save or update accordingly.
>>
>> Problem 2:
>>
>> An exception is thrown of the form
>>
>> 10:00:40,359 WARN JDBCExceptionReporter:77 - SQL Error: 1062,
>> SQLState: 23000
>> 10:00:40,359 ERROR JDBCExceptionReporter:78 - Duplicate entry
>> 'urn:sdmx:org.sdmx.infomodel.base.Agency=SDMX' for key 1
>> org.hibernate.exception.ConstraintViolationException: Could not
>> execute JDBC batch update....etc etc
>>
>> It seems again that hibernate is not differentiating between existing
>> and new objects but this time it gets further and is attemtping to put
>> the object into the DB, but with a save instead of an update. Should
>> Teneo/Hibernate be able to handle this mixture of new and existing
>> elements.
>>
>> -------------
>>
>> Ive looked through the Hibernate forums extensively on this issue and
>> I cant seem to find any exact related issues. Im thinking that my
>> problem is more to with EMF and Teneo and the semantics of how they
>> interact with Hibernate......but I could be on totally the wrong track.
>>
>> Anyone ever tried anything similiar to the above .. ?
>>
>> Any help is greatly appreciated as always.
>>
>> Duncan
>
>
Re: [TENEO] Hibernate update exception when updating existing data [message #606996 is a reply to message #86518] Fri, 15 June 2007 11:44 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Duncan,
1) Hmm, what I can think of is the following: what can happen is that when saving part of the xml
tree an object from another part of the tree is loaded from the db (because there are references to
it), then when the other part of the tree is updated, hibernate finds that it already has an
instance with the same id.
2) I would need to run a testcase to get a better feel for what goes wrong there.

Can you make a small testcase for both cases?

gr. Martin

Duncan ALexander wrote:
> Hi,
> I have an EMF model which I have persisted into a DB using Teneo and
> Hibernate. My EMF model is initially loaded from an XML document and
> calling save on the root of the object graph will correctly persist the
> document into the DB.
>
> In my application I am trying to deal with new xml documents which may
> contain new elements for persisting or updates to existing elements
> which were persisted from previous XML document submissions.
>
> Test 1:
>
> As a basic test I have loaded an initial XML document into my EMF model
> then persisted this to the DB. I then attempted to load exactly the same
> document and perform a session.update() passing in the root of the
> object graph . Sounds reasonable, it should overlay the object values on
> top of the old ones and increment the version of each persisted object
> in the DB.
>
> Problem 1:
>
> An exception is thrown of the form
>
> org.hibernate.NonUniqueObjectException: a different object with the same
> identifier value was already associated with the session:
> [cat.CategoryScheme#urn:sdmx:org.sdmx.infomodel.categorysche me.CategoryScheme=SDMX:categoryScheme1]
>
>
> I am running this test in isolation so I have created a brand new
> session from Teneo, then I have called empty() just to be sure, then
> when I perform my update( ) I see the error above. Am I missing
> somethign here? How can the object possibly already be in the session ?
>
> -----------
>
> Test 2:
>
> I load an initial XML document into my EMF model and persist this
> through Teneo/Hibernate to the DB. I then attempt to load a new XML
> document which contains some new elements and one existing element. I
> then call saveOrUpdate on the datagraph root. I would expect in this
> instance for hibernate to be able to differentiate between new and
> existing elements and perform a save or update accordingly.
>
> Problem 2:
>
> An exception is thrown of the form
>
> 10:00:40,359 WARN JDBCExceptionReporter:77 - SQL Error: 1062, SQLState:
> 23000
> 10:00:40,359 ERROR JDBCExceptionReporter:78 - Duplicate entry
> 'urn:sdmx:org.sdmx.infomodel.base.Agency=SDMX' for key 1
> org.hibernate.exception.ConstraintViolationException: Could not execute
> JDBC batch update....etc etc
>
> It seems again that hibernate is not differentiating between existing
> and new objects but this time it gets further and is attemtping to put
> the object into the DB, but with a save instead of an update. Should
> Teneo/Hibernate be able to handle this mixture of new and existing
> elements.
>
> -------------
>
> Ive looked through the Hibernate forums extensively on this issue and I
> cant seem to find any exact related issues. Im thinking that my problem
> is more to with EMF and Teneo and the semantics of how they interact
> with Hibernate......but I could be on totally the wrong track.
>
> Anyone ever tried anything similiar to the above .. ?
>
> Any help is greatly appreciated as always.
>
> Duncan


--

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] Hibernate update exception when updating existing data [message #606997 is a reply to message #86535] Fri, 15 June 2007 12:11 Go to previous message
Duncan Alexander is currently offline Duncan AlexanderFriend
Messages: 90
Registered: July 2009
Member
Hi Martin,
I have a small test case but I have included my full set of ecore files and my full hibernate
mapping as Im not confident that I can detach subsections from them.

I have forwarded these directly to you as they are owned by a customer.

My test code would do the following (TeneoSessionManager handles the setup of the DBDataStore):

// LOAD AND SET THE INITIAL DB STATE
teneoSession = TeneoSessionManager.getInstance();
teneoSession.empty();
EDataGraph externalIMAsDatagraph =
StructureMother.INSTANCE.getExternalIMAsDatagraph(
"/resources/TEST_1.X_SDMXIM_REGISTRY_BASE.xml");
Session session = teneoSession.getSession();
Transaction transaction = session.getTransaction();
transaction.begin();
session.save(externalIMAsDatagraph.getERootObject());
session.flush();
transaction.commit();
session.close();

// ATTEMPT TO LOAD A FURTHER DOCUMENT AND UPDATE THE DB STATE
// BY SAVEORUPDATING EACH INDIVIDUAL ELEMENT IN THE DOCUMENT.
EDataGraph externalIMAsDatagraph =
StructureMother.INSTANCE.getExternalIMAsDatagraph(
"/resources/TEST_1.1_SDMXIM_DUPLICATE_CONCEPT_SCHEME.xml"); SDMXContainer sdmxContainer =
(SDMXContainer) externalIMAsDatagraph.getERootObject();
Session session = teneoSession.getSession();
Transaction transaction = session.getTransaction();
transaction.begin();
List identifiableList = sdmxContainer.getIdentifiable();
for (Object o : identifiableList) {
session.saveOrUpdate(o);
}
session.flush();
transaction.commit();
session.close();

-------------------------------------------------

From the above I would expect to see the Concept Scheme updated with one new concept (concept3) and
one updated concept(concept1) and one concept deleted (concept2)

Duncan



Martin Taal wrote:
> Hi Duncan,
> 1) Hmm, what I can think of is the following: what can happen is that
> when saving part of the xml tree an object from another part of the tree
> is loaded from the db (because there are references to it), then when
> the other part of the tree is updated, hibernate finds that it already
> has an instance with the same id.
> 2) I would need to run a testcase to get a better feel for what goes
> wrong there.
>
> Can you make a small testcase for both cases?
>
> gr. Martin
>
> Duncan ALexander wrote:
>> Hi,
>> I have an EMF model which I have persisted into a DB using Teneo
>> and Hibernate. My EMF model is initially loaded from an XML document
>> and calling save on the root of the object graph will correctly
>> persist the document into the DB.
>>
>> In my application I am trying to deal with new xml documents which may
>> contain new elements for persisting or updates to existing elements
>> which were persisted from previous XML document submissions.
>>
>> Test 1:
>>
>> As a basic test I have loaded an initial XML document into my EMF
>> model then persisted this to the DB. I then attempted to load exactly
>> the same document and perform a session.update() passing in the root
>> of the object graph . Sounds reasonable, it should overlay the object
>> values on top of the old ones and increment the version of each
>> persisted object in the DB.
>>
>> Problem 1:
>>
>> An exception is thrown of the form
>>
>> org.hibernate.NonUniqueObjectException: a different object with the
>> same identifier value was already associated with the session:
>> [cat.CategoryScheme#urn:sdmx:org.sdmx.infomodel.categorysche me.CategoryScheme=SDMX:categoryScheme1]
>>
>>
>> I am running this test in isolation so I have created a brand new
>> session from Teneo, then I have called empty() just to be sure, then
>> when I perform my update( ) I see the error above. Am I missing
>> somethign here? How can the object possibly already be in the session ?
>>
>> -----------
>>
>> Test 2:
>>
>> I load an initial XML document into my EMF model and persist this
>> through Teneo/Hibernate to the DB. I then attempt to load a new XML
>> document which contains some new elements and one existing element. I
>> then call saveOrUpdate on the datagraph root. I would expect in this
>> instance for hibernate to be able to differentiate between new and
>> existing elements and perform a save or update accordingly.
>>
>> Problem 2:
>>
>> An exception is thrown of the form
>>
>> 10:00:40,359 WARN JDBCExceptionReporter:77 - SQL Error: 1062,
>> SQLState: 23000
>> 10:00:40,359 ERROR JDBCExceptionReporter:78 - Duplicate entry
>> 'urn:sdmx:org.sdmx.infomodel.base.Agency=SDMX' for key 1
>> org.hibernate.exception.ConstraintViolationException: Could not
>> execute JDBC batch update....etc etc
>>
>> It seems again that hibernate is not differentiating between existing
>> and new objects but this time it gets further and is attemtping to put
>> the object into the DB, but with a save instead of an update. Should
>> Teneo/Hibernate be able to handle this mixture of new and existing
>> elements.
>>
>> -------------
>>
>> Ive looked through the Hibernate forums extensively on this issue and
>> I cant seem to find any exact related issues. Im thinking that my
>> problem is more to with EMF and Teneo and the semantics of how they
>> interact with Hibernate......but I could be on totally the wrong track.
>>
>> Anyone ever tried anything similiar to the above .. ?
>>
>> Any help is greatly appreciated as always.
>>
>> Duncan
>
>
Previous Topic:[TENEO] Hibernate update exception when updating existing data
Next Topic:[Teneo] : VersionPropertyHandler returns null for dettached objects
Goto Forum:
  


Current Time: Thu Mar 28 23:15:37 GMT 2024

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

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

Back to the top