-->
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.  [ 2 posts ] 
Author Message
 Post subject: Single component mapping to multiple rows?
PostPosted: Thu Feb 12, 2004 7:18 pm 
Newbie

Joined: Thu Feb 12, 2004 6:19 pm
Posts: 10
My (legacy) data model includes a pair of tables along the lines of

Code:
table Item (
    item_id integer,
    description varchar
)

table Attribute (
    attribute_id integer,
    item_id integer,
    category varchar,
    description varchar
)


The existing code that manipulates those tables exposes the data using the Composite pattern, with a top-level node representing the Item row, a synthetic set of second-level nodes with the category values as their descriptions (the "id" properties of those nodes are ignored), and leaf nodes under each of the categories with the actual descriptions.

How would you map that object model to the tables using Hibernate? It seems like components would almost work, except that a single second-level node can represent more than one row in the Attribute table.

The only approach that's coming to mind right now is to map the Attribute table to a flat collection under the Item class, then provide a method to scan the collection and generate the hierarchy using non-persistent objects that refer back to the persistent ones. Any better ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 7:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can not map one entity to multiple table rows. I would suggest you fix your database design if you can (use a view or something), if you can. Otherwise you have to use a workaround like the list mapping you suggested.


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

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.