• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate incorrect replacement of Class in Named Query

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic