RE: detached entity semantics and ManyToOne OneToOne

View: New views
1 Messages — Rating Filter:   Alert me  

RE: detached entity semantics and ManyToOne OneToOne

by nhhockeyplayer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

correction on the title...
detached entity semantics and ManyToOne OneToMany


Best regards
Ken in nashua





From: nhhockeyplayer@...
To: users@...
Subject: detached entity semantics and ManyToOne OneToOne
Date: Fri, 14 Mar 2008 11:37:32 -0400

Jira's have been entered regarding the current solution to detached entity coillections.
 
Regardless...
 
This appears to be the accurate solution.
 
HibernatePersistenceServiceImpl.JAVA

@Transactional

public void reattach(Object model)

{

try {

getSession().lock(model, LockMode.NONE);

} catch (org.hibernate.NonUniqueObjectException ex) {

merge(model);

}

}
 
ManyToOne annotation should at least be operated as follows:
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } )
 
OneToMany annotation seems ok as follows:
@OneToMany(cascade=CascadeType.ALL)
 
These seem to mitigate LazyInitializationExceptions, NonUniqueObjectExceptions and deletion of parent delegates via misuse of CascadeType.ALL which will rampantly travel up the object graph and delete entities not intended to be deleted.



Best regards
Ken in nashua




Shed those extra pounds with MSN and The Biggest Loser! Learn more.


Need to know the score, the latest news, or you need your HotmailĀ®-get your "fix". Check it out.
Best regards
Ken in nashua
LightInTheBox - Buy quality products at wholesale price!