-->
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.  [ 5 posts ] 
Author Message
 Post subject: need help...ATTN Gavin!
PostPosted: Tue Feb 10, 2004 5:00 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 5:08 am
Posts: 21
How will you create a table on this? I have:

public class ContactRole {
private String id;
private String name;
private ContactRole partner;
}

where if we have,

ContactRole contactRoleA = new ContactRole();
ContactRole contactRoleB = new ContactRole();

contactRoleA.setPartner(contactRoleB);
contactRoleB.setPartner(contactRoleA);

Both can only exist only once. Where if i have an Employee as ContactRoleA and Employer as ContactRoleB, this cannot be repeated again in any instance like Employee ContactRoleA and Consultant ContactRoleB. This should be illegal.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 5:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well I don't get exactly what you are saying here, but you should be able to do this with unique constraints in the DB. Place an unique constraint on the id and the relation fk for partner (in combination).

PS: Please try to use proper subjects in your posts.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 5:15 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 5:08 am
Posts: 21
Yes, creating this in the table directly is easy. But what i meant is creating this via hibernate-mapping. Is this available in hibernate? Currently i have this mapping:

<hibernate-mapping>
<class name="com.eon.cms.vo.ContactRole" table="contact_role">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="partner" column="role_id_2"/>
<property name="name" length="50"/>
</class>
</hibernate-mapping>

But i dont think part

<many-to-one name="partner" column="role_id_2"/>

is pointing to the ContactRole too...

please clarify...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 5:22 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gloeglm wrote:
PS: Please try to use proper subjects in your posts.

Yes it's very annoying for people helping ion this forum.

Can you elaborate your needs, you don't give enough information.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 4:30 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 5:08 am
Posts: 21
ok here it goes:

id name partner_id
1 Employee 2
2 Employer 1
3 Friend 3
4 Consultant 4
5 Consumer 6
6 Producer 5


right now with my mappings, im inserting data to contact_role by :

Add
1. create the first ContactRole (new ContactRole("Employee");
2. save contactRoleA (the partner id is still null)
3. create the second ContactRole ( new ContactRole("Employer");
4. set the partner id of the second one with the first one then save
5. edit the first one and set its partner id to the second record then
save

* there's no problem if the record is the same (like the Friend) i only need to add once but with two records i need to do those steps.
* name is unique

Edit
1. Load the two objects and check which one has change then delete the other one

Lets say i want to edit Employee so that its partner will be Consumer
so Employer and Producer will be deleted since a record can only have one partner.

* but what if the records point to itself ( like Friend)?


Is there a better way to do this?


thanks....

raymond


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.