[hibernate-dev] Secondary table support 5.0

Steve Ebersole steve at hibernate.org
Wed Apr 18 09:55:42 EDT 2012


Secondary table support is pretty much done on the metamodel branch. 
One thing we should discuss is support for using property-ref in 
conjunction with <key/> there in hbm.xml.

Hibernate has never supported this.  But I wanted to look at adding 
support for it in 5.0 with these metamodel changes.  What I found is 
that we *could* support it, but that would mean a few changes and 
"limitations".

First, the limitations come down to:
1) property-refs would have to be limited to naming properties whose 
columns are part of the primary table.  I don't think this is a huge 
deal in practice.
2) hbm.xml does not support "nested" secondary tables.  Basically it is 
assumed that all foreign keys across all secondary tables reference back 
to the primary table.

We could somewhat alleviate these limitations by allowing the nesting of 
joins.  This starts to get complicated to support in-and-of-itself 
though.  But in this approach, property-refs could name properties 
defined as part of any <join/> mappings "above" the one being defined or 
the primary table.

The major change this requires in processing comes in Binder. 
Currently, when processing an entity, we:
1) bind the primary table,
2) bind its identifier,
3) bind its (if any) secondary tables,
4) bind attributes.
Essentially we follow the JPA model here where the "column sources" name 
the table to which they belong (and adapt the hbm.xml model to that 
case).  However, to support hbm.xml property-refs at all we will need to 
change that process.  In the approach of not allowing nested secondary 
tables, the process would become:
1) bind the primary table
2) bind its identifier
3) *** bind any attributes mapped to the primary table ***,
4) bind its (if any) secondary tables,
5) bind attributes coming from secondary tables
And in terms of allowing the nesting of secondary tables, the process 
then needs to become essentially the same as above, but we would need to 
process attributes from each secondary table as we process the secondary 
table.  Interestingly, these approaches more naturally follow the 
hbm.xml model.

I guess the first thing to discuss is whether we want to add support for 
<key property-ref/> in regards to <join/> for hbm.xml.  We kind of want 
to steer people to use annotations anyway, so maybe we just decide this 
is not worthwhile.  WDYT?

-- 
steve at hibernate.org
http://hibernate.org


More information about the hibernate-dev mailing list