aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate incorrect replacement of Class in Named Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate incorrect replacement of Class in Named Query" Watch "Hibernate incorrect replacement of Class in Named Query" New topic
Author

Hibernate incorrect replacement of Class in Named Query

Matt LeVan
Greenhorn

Joined: Aug 13, 2010
Posts: 3
I have two java classes, CurrentData and HistoricData, where HistoricData extends CurrentData.

There is no relationship implied or intended between the hibernate mappings, the tables are almost identical, but where one has a currentFkId column the other has a historicFkId column.

While this might be a weird situation, I don't believe it should break any of Hibernate's assumptions. However, we have a Named Query with the HQL , and for some as yet unknown reason, when Hibernate tries to render that query, it replaces the parent class with it's sub-class, rendering the above HQL as and throws an Exception pasted below.

Why has Hibernate decided to take my perfectly legitimate Class name, and replace it with an arbitrary sub-class? It runs counter to all the Java conventions. On the assumption that this is an issue with Hibernate, I've tried rearranging the order of the Mapping files in my hibernate.cfg to see if the order of class registration matters, and I've added a hibernate.query.substitution rule that explicitly mapped CurrentData=org.mycompany.CurrentData. Neither change seemed to have any effect.

Any advice you're able to offer, either in explaining what's going on, or in suggesting ways to get my desired behavior would be most welcome.

Thanks in advance,

matt


Matt LeVan
Greenhorn

Joined: Aug 13, 2010
Posts: 3
Poster's bane. I found the answer based on this post off this NHibernate forum thread

The default state for the class, "polymorphism='implicit'" allowed it to pick up the sub-class, changing the polymorphism to "explicit" on the CurrentData class resolved my issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate incorrect replacement of Class in Named Query