Matt LeVan

Greenhorn
+ Follow
since Aug 13, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Matt LeVan

Hi,

I'm having weird issues trying to use fetch="join" on the properties of more than one subclass of my hibernate mapping file.

First, the situation: I have a constellation of one-to-many tables related by foreign key to a single parent table. The parent table defines the superclass, then overlapping subsets of the related tables define the subclasses. So subclass A will have sets of type (X, Y, and Z) and subclass B will have sets of type (X, V, and W) .

The Hibernate Mapping file looks like this:

The Criteria query used looks like this:


Now, when I execute that Criteria (in order to get both As and Bs back), the select statement output joins V, W, X, Y, and Z (just like you'd think it would). Attempts to access a returned object of type A's properties are successful without Lazy loading (as I want it to be), but any attempt to access an object of type B's properties results in them being lazy loaded, even though they should be available.

But it gets weirder! Which subclass has immediate access to the SELECTed information is position dependent! If I swap subclass B above subclass A in the mapping file, then it works fine, while class A does the lazy loading.

I've also tried moving class A out to an external mapping file, but the behavior is the same, it still insists on lazy loading its properties.

If anybody has seen this before and has a solution, or even has a suggestion about what I should try next, I would be extremely grateful. It seems to me that any behavior that treats one sibling differently from another is not working as designed.

Thanks for your time,

matt
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 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