Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Teneo/Hibernate NonUniqueObjectException resolving
Teneo/Hibernate NonUniqueObjectException resolving [message #427492] Thu, 19 February 2009 15:42 Go to next message
Mikhail Kadan is currently offline Mikhail KadanFriend
Messages: 61
Registered: July 2009
Member
I have next method:

public static Serializable getId(Session session, Object object) {
Serializable id = null;
try {
session.lock(object, LockMode.NONE);
id = session.getIdentifier(object);
} catch (NonUniqueObjectException e) {
throw new RuntimeException(e);
} catch (TransientObjectException e2) {
id = session.save(object);
}
return id;
}

I want to change catcher for NonUniqueObjectException to return valid
value, not just chain exception on top level. I have to return my object's
id:

id = object.getId();

But as I understand Teneo adds id field dynamically, and I don't have it
in EMF model, so I cannot access it in a regular way. How can I get id of
my object in this situation?
Re: Teneo/Hibernate NonUniqueObjectException resolving [message #427519 is a reply to message #427492] Thu, 19 February 2009 19:42 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mikhail,
For virtual/synthetic id's Teneo keeps the Id's in a separate cache. So you can also do this:
Serializable id = (Serializable) IdentifierCacheHandler.getInstance().getID(object);

Note that for live/production software it is recommended to have a real id-attribute and not to use synthetic id's.

gr. Martin

Mikhail Kadan wrote:
> I have next method:
>
> public static Serializable getId(Session session, Object object) {
> Serializable id = null;
> try {
> session.lock(object, LockMode.NONE);
> id = session.getIdentifier(object);
> } catch (NonUniqueObjectException e) {
> throw new RuntimeException(e);
> } catch (TransientObjectException e2) {
> id = session.save(object);
> }
> return id;
> }
>
> I want to change catcher for NonUniqueObjectException to return valid
> value, not just chain exception on top level. I have to return my
> object's id:
>
> id = object.getId();
>
> But as I understand Teneo adds id field dynamically, and I don't have it
> in EMF model, so I cannot access it in a regular way. How can I get id
> of my object in this situation?
>


--

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/Hibernate NonUniqueObjectException resolving [message #427524 is a reply to message #427519] Fri, 20 February 2009 07:34 Go to previous messageGo to next message
Mikhail Kadan is currently offline Mikhail KadanFriend
Messages: 61
Registered: July 2009
Member
> Note that for live/production software it is recommended to have a real
> id-attribute and not to use synthetic id's.

Can you explain this part a bit more? Why it is not recommended to use
synthetic id's? Or maybe you can give a link which explains this?

Thanks.
Re: Teneo/Hibernate NonUniqueObjectException resolving [message #427525 is a reply to message #427524] Fri, 20 February 2009 07:51 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mikhail,
It depends a bit on your specific case. The main thing is that the synthetic id will not work if you serialize and
deserialize objects. As the Teneo synthetic id works using weak references and object equality.
Before we had some problems with memory leaks in the synthetic id part but that is solved.
And as a last remark overall I find it easier if the id of the object travels with the object itself. (but that's just
my personal opinion)

So if you don't serialize/deserialize then there are no obstacles in using synthetic id's.

Note that next to the synthetic id there is also the synthetic version which is kept behind the scenes if you don't have
an explicit version eattribute.

gr. Martin

Mikhail Kadan wrote:
>> Note that for live/production software it is recommended to have a real
>> id-attribute and not to use synthetic id's.
>
> Can you explain this part a bit more? Why it is not recommended to use
> synthetic id's? Or maybe you can give a link which explains this?
>
> Thanks.
>


--

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
Previous Topic:Model Question.
Next Topic:Serialize an EObject without changing its resource
Goto Forum:
  


Current Time: Fri Apr 26 19:45:56 GMT 2024

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

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

Back to the top