-->
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: Confused On Type Of Mapping Needed
PostPosted: Mon Sep 15, 2008 2:37 pm 
Newbie

Joined: Thu Aug 21, 2008 4:33 pm
Posts: 2
Hello,

Hibernate 3.x.

I am getting confused on what type of mapping to use in the following scenario.

I have a table lets call it A.
It has a PK (surrogate).

-------------------------
TABLEA
int id (PK)
varchar type NOT NULL
---------------------------

This is mapped as an entity with a sequence, all good here.

Now it has a assocaition to TABLEB
----------------------------
TABLEB
int id (PK/FK) // This is from TABLEA PK and is a FK.
varchar type (PK) // this is from TABLEA and is also a PK
------------------------------------------------

I have been reading through the different types of mappings, and I cannot figure out what this is? I believe TABLEB will be a composite mapping, but I am having trouble figuring out how to map and create with java.

Table A will have a 1 to many of B, so 1 has a set of B.

I figured I could instantiate a TABLEA object, then create a TABLEB object, and add TABLEB to a set in TABLEA, then save TABLEA.

So is TABLEB a entity? (NO HBM) or a value type (I BET IT IS).

Could someone please assist with information on this type of mapping? Any book pages (in Action) book. Or references for this?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 10:19 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
The problem is that your table design is nor really relational.
Foreign keys shout be the exact same primary keys on the referred table.

If you had the same amount of field for PK on both tables (ideally, just ID), then your case would be a "one-to-one association on a primary key", which is an association described in item 7.4.2 of the documentation

http://www.hibernate.org/hib_docs/v3/re ... tions.html

_________________
Gonzalo Díaz


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.