aspose file tools*
The moose likes Object Relational Mapping and the fly likes Joined Strategy Inheritance problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Joined Strategy Inheritance problem" Watch "Joined Strategy Inheritance problem" New topic
Author

Joined Strategy Inheritance problem

Martin Castellanos
Greenhorn

Joined: Sep 23, 2008
Posts: 10
Hello, I'm new in this community, I already posted this issue in the Hibernate forums with no luck, I'd appreciate any help.

I have the following inheritance:



The problem is that a Manager can also be a Director, and when that happens I'm getting an org.hibernate.WrongClassException if I try to query on Manager.

I'm testing the query with Hibernate Tools.
This is the HQL:


The generated query is:




But when I run the query from the application:


This is the generated query:



Hibernate version: Hibernate EntityManager 3.2.0.CR1, Hibernate Annotations 3.2.0.CR1, Hibernate 3.2 cr2. We are using JPA: ejb3-persistence

Full stack trace of any exception that occurs:


Name and version of the database you are using: MySQL 5


Thanks in advance
Regards.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17256
    
    6

Just out of curiosity, what happens if you assign it to List<User> rather than assign it to List<Manager>. Not that it helps you much, but I don't have a real good answer for you.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Martin Castellanos
Greenhorn

Joined: Sep 23, 2008
Posts: 10
Hello Mark,

Thanks for your reply, it's the same result because the exception is thrown inside the query.getResultList() method.

Regards
Martin Castellanos
Greenhorn

Joined: Sep 23, 2008
Posts: 10
I just tried removing the left join and now the generated query is:



But I keep getting the same exception.
Any ideas?

[ September 23, 2008: Message edited by: Martin Castellanos ]
[ September 23, 2008: Message edited by: Martin Castellanos ]
Martin Castellanos
Greenhorn

Joined: Sep 23, 2008
Posts: 10
I finally found the cause.
The problem was that I had already loaded one of the Managers but as an User object, when I tried to load the list of Managers, hibernate checks if the objects are already in the persistence context, since the object was in the persistence context hibernate uses that object, and when it checks if the object is an instance of Manager, fails and throws the WrongClassException.

I ended up changing the implementation of the relationships to an association instead.

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Joined Strategy Inheritance problem