Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Joined Strategy Inheritance problem

 
Martin Castellanos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martin Castellanos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic