Yeah, you have to detach, or it maintains extra data in the CGLIB-constructed objects that tell it that the object has an identity in the database.

Not sure what the "null" value is for primitive longs. You could use the unsaved-value attribute in the mapping file to tell hibernate explicitly that "-1" means "new object".

Hibernate is not particularly friendly to swing GUI apps.
Since they don't have defined request/response cycle it can get quite icky.

Be careful of the long conversion pattern, it is easy to leak memory that way.

I open and close sessions everywhere I talk to hibernate, which is a little verbose, but stops leaks

Sometimes I will pass the session object around inside a class. But I never store the session object on a field.


On 5/4/06, Enrico Goosen <[EMAIL PROTECTED]> wrote:

The plot thickens…

 

Is it really necessary to detach the object graph from the session?

I'm using the session-per-conversation pattern (long conversation), because my Swing gui application doesn't work well Hibernate session-per-request pattern.

 

Setting the IDs to null is also a problem, because I'm using long (primitive type) for the IDs.

When I set the ID to -1, I get a NonUniqueObjectException.

 

What to do…what to do…

 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Noel Grandin
Sent: 04 May 2006 10:09 AM
To: [email protected]
Subject: [CTJUG Forum] Re: Hibernate guru's

 

Hmmm, detaching the object will make it "new" from hibernate's point of view.
Then if you set the IDs to null, and persist it, it should create a new object graph.

But I'm not sure how you would make this recurse down an object graph.
It would probably depend on what the cascade attribute in the mapping file was set to.

On 5/4/06, Enrico Goosen < [EMAIL PROTECTED]> wrote:

Is it possible to clone and persist an object graph in Hibernate?

I've come across the org.hibernate.util.SerializationHelper 
which can be used to clone an object graph, but I don't think that it can be persisted, since its id's will be the same as the original object graph.

 

Any ideas?

 

Enrico Goosen

Software Developer

SAICOM TECHNOLOGY

TEL:       +2721 417 1375

FAX:     +2721 417 1361

CEL:     +2783 305 5676

EMAIL: [EMAIL PROTECTED]

 

 







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
-~----------~----~----~----~------~----~------~--~---

Reply via email to