File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Non Persistable POJO extending a persistable POJO

 
Priya Venkatesan
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Down-casting might not work, can you make B replicate hbm file and keep A as transaction object??
 
Priya Venkatesan
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please add more clarification?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can't you not pass (non-persistent) Object B to this method. What is the exception you are getting?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On second thought, check if it related to hibernate proxy?
 
Edvins Reisons
Ranch Hand
Posts: 364
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you call the class B non-persistable? Is there anything that prevents you from mapping it?
 
Priya Venkatesan
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic