Monday, July 21, 2008

HIbernate join tables or xref tables or cross reference tables or cross-reference tables

I just spent a bit of time figuring out how to do bidirectional one-to-many mappings that are associated with a join table / xref / cross reference / cross-reference (I'm spelling all of these out in the event that some other poor soul is searching those terms) and exist in separate schemas.

Its actually spelled out (not the separate schema part, but that's easy) on the hibernate site which shouldn't be surprising since its an excellent site.

There are two tricks to making this work :
  1. Map the children into the parent as a many-to-many, but set "unique='true'" in the mapping.
  2. Map the join table into the child object.

In my case this meant something along the lines of this in the parent :
<set name="children" table="XREF" schema="PARENT_SCHEMA"
lazy="false" inverse="true">
<key column="XREF_PARENT_ID" not-null="true" />
<many-to-many unique="true" column="XREF_CHILD_ID" class="com.jeremyrdavis.Child" />

And this in the child :
<join table="PARENT_SCHEMA.XREF" inverse="true" optional="true" >
<key column="XREF_CHILD_ID" not-null="true" />
<many-to-one name="group" column="XREF_PARENT_ID" not-null="true"></many-to-one>

Blogged with the Flock Browser

Wednesday, July 16, 2008

Terracotta at July's AJUG

Last Tuesday's AJUG (that's the Atlanta Java User's Group) presentation by Kunal Bhasin, a field engineer at Terracotta, ruled.  First of all, Kunal did a bang up job of fielding a ton of questions, and most of crowd stayed around an extra half hour for his presentation.  Second, Terracotta has a seriously cool app.  

I've attend AJUG regularly (meaning most of them) for the past few years.  Burr Sutter who runs AJUG and is the product manager for JBoss ESB does a great job with the speakers, but there have been a few that really stand out.  I got introduced to both Hibernate and Spring (although I had read about Hibernate previously) a few years back at AJUG meetings, and on both occasions got the feeling that those technologies were not only worth using but would be really big.  I got a similar impression about Terracotta; although, its nothing like either Hibernate or Spring.  Its actually pretty invisible to developers, which is the point.

In a nutshell (echoes of O'Reilly?) Terracotta's server(s) controls the objects for numerous JVMs allowing applications from each to access the same instances without any special apis.   I'm sure there's plenty of information on their site, and if you are an architect or have had to worry about clustering, caching or scaling then check it out.  They have separate sites for the commercial and open source versions (a lot like and - is this going to be the standard for oss business models now?)

Bill Sengstacken, who is in marketing, is going to post a video, and there should be a link on the AJUG site at some point.