It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes ejb3unit and persistence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ejb3unit and persistence" Watch "ejb3unit and persistence" New topic
Author

ejb3unit and persistence

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Hi,

In my test class there is a call to persist an object.

Following is the class code snippet which save the object.


INFO: Exception occured org.ejb3unit.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before merging: com.text.domain.ABC

Also the object I am passing in the test class is not transient also...so why this exception occurs?

Thank You.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

Harshana,
Can you show some more code? How does "object" get created?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Sorry for the late reply Jeanne..well its like this,

Well I create a that object which is type PQR using new() in my EJBUnit class..where that PQR object has a relationship with ABC like following,



So what i realise is when using merge() we have to use a PQR object which exists in database rather create new one and that exception goes.
And with persist() that doest matter even object is created newly or already exists in DB...(mm not sure about that..have to try it..)

So the difference is come from the difference of mereg() and persist() method..where in merge method cant apply to new objects which does not persist in database right? so can some one elaborate this fact more theoretically what is the reason?

Thank You.






Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

Moving to ORM forum since this is now a question about how JPA/EJB 3 works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ejb3unit and persistence