-->
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: Mapping Contact and ContactPartial using a single DB table
PostPosted: Sat Jun 17, 2006 9:16 am 
Newbie

Joined: Sat Jun 17, 2006 9:00 am
Posts: 1
Hibernate version:
Hibernate Core 3.2.CR2
Annotations 3.2.CR1
EntityManager 3.2 CR1

Hi guys,

this is more of a principal question on how to design my mapping. I've did the same scenario using plain old JDBC already and wanted to use this as a first test of the EJB3 stuff.

I want to model a group containing contacts.

I've got three DB tables:
- Contact (contact_id, firstname, lastname,...)
- Group(group_id, name, ...);
- Members(group_id,contact_id)

The contact and group tables contain a lot more attributes of course. For this reason, I created two subset classes of Contact and Group:
- ContactPartial
- GroupPartial
They both contain only a small subset of the information needed. Only if I need more, I want to retrieve the whole Contact or Group object from the DB.

Only the Contact and Group classes are entities. Both partial classes are retrieved whenever I need only a subset of the information.

My GroupPartial object manages a list of ContactPartial objects.

@OneToMany(fetch = FetchType.LAZY, targetEntity = ContactPartial.class)
@JoinTable(
name="MEMBERS",
joinColumns = { @JoinColumn( name="GROUP_ID") },
inverseJoinColumns = @JoinColumn( name="CONTACT_ID")
)
private List<IContactPartial> members = new ArrayList<IContactPartial>();

Problem is of course, that this is not possible as long the ContactPartial is not an entity of itself.

But, this is not as I want it! I want the ContactPartial "reuse" the data from the DB table of Contact.

I tried to make them use the same table and column names (using @Table(name="CONTACT")), but this throws me error messages.

Is there a way of mapping this behaviour? I would rather prefer do define an elegant mapping, instead of handcoding my queries.


Many thanks in advance,
-Frederik


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.