-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Inheritance model too weird for Hibernate to handle?
PostPosted: Wed Mar 31, 2010 1:17 pm 
Newbie

Joined: Wed Mar 31, 2010 12:42 pm
Posts: 1
Hi there,

First post here and hopefully not my last!

I'm working on a project now where we're trying to replace our lame data access layer with Hibernate. Problem is that our current inheritance model is quite tricky to capture. This is a really interesting use case for Hibernate so hopefully I'll get some great responses!

The database tables look like this:

BASEENTITY
-ID
-LINKID
-STUFF

TRADE
-ID

INSTR
-ID


And the Java object hierarchy is that BaseEntity is the superclass with Trade and Instr (and others) as the subclass.

Here's the rub...

The ID fields on the 3 tables do NOT express a hierarchy. They are unique to each table only. You cannot look up a Trade's BaseEntity by using the trade ID and finding a matching ID in BaseEntity.

The connection is actually the BASEENTITY.LINKID field. The LINKID matches IDs in the TRADE or INSTR table. Like this:

BASEENTITY
ID=1, LINKID=100
ID=2, LINKID=200

TRADE
ID=100

INSTR
ID=200


This is a problem in hibernate. We hoped to use multiple unidirectional one to one relationships but you have to annotate both ends so the LINKID field can only take one reverse link!
We then tried marking BaseEntity with Inheritance type 'table per class'. but Hibernate freaks out because it states that you can't override the 'ID' field in the subclasses. It doesn't realise they're not related!

After this the only solutions we can currently come up with are to not use Hibernate for the inheritance and actually have some delegate class which looks up the BaseEntity data for you as required e.g.

BaseEntityDelegate.lookupBaseEntityDate(BaseEntity b);//runs a sql db hit and sets values on BaseEntity

But this is pretty lame.

An elegant solution to this would be awesome!

Regards,
John


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.