| 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: 508
|
|
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: 508
|
|
|
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
|
 |
 |
|
|
subject: Non Persistable POJO extending a persistable POJO
|
|
|