This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Non Persistable POJO extending a persistable POJO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Non Persistable POJO extending a persistable POJO" Watch "Non Persistable POJO extending a persistable POJO" New topic
Author

Non Persistable POJO extending a persistable POJO

Priya Venkatesan
Ranch Hand

Joined: Nov 02, 2002
Posts: 61
I have a legacy application which we are migrating to hibernate and
I have a situation where a non peristable POJO extends a persistable POJO and this non persistable is passed on to an API which is then persisted using the hibernate API.

(e.g) B extends A

public createObject(A a)
{
//get hibernate sessionFactory, session
session.save(a);
}

Code which makes use of this API

public void caller(B b)
{
createObject(b);
}

This obviously is not working since hibernate is looking for a mapping for B which I do not have. Is there a way to make this work?
sathish kumar
Ranch Hand

Joined: Feb 14, 2007
Posts: 47
Down-casting might not work, can you make B replicate hbm file and keep A as transaction object??
Priya Venkatesan
Ranch Hand

Joined: Nov 02, 2002
Posts: 61
Can you please add more clarification?
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513



Can't you not pass (non-persistent) Object B to this method. What is the exception you are getting?


If you are not laughing at yourself, then you just didn't get the joke.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

On second thought, check if it related to hibernate proxy?
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
Why do you call the class B non-persistable? Is there anything that prevents you from mapping it?
Priya Venkatesan
Ranch Hand

Joined: Nov 02, 2002
Posts: 61
Thanks for all your response. I got this figured out. All that I had to do was to map B to same table as its parent and specify polymorphism="explicit" in order for hibernate to return only instances of B.

I found my solution here:

http://www.hibernate.org/41.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non Persistable POJO extending a persistable POJO