-->
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.  [ 4 posts ] 
Author Message
 Post subject: relation with property?
PostPosted: Wed May 04, 2005 7:25 am 
Newbie

Joined: Mon May 02, 2005 3:31 pm
Posts: 4
Hibernate version:2

I have a very small question:
Is it possible to make a relation (eg. many-to-many) with a propery?

Something like:
Code:
<set name="groups" table="user_group">
      <key column="user_id"/>
      <many-to-many class="group" column="group_id"/>
      <propery name="relProp" type="string"/>
</set>


???

_________________
/~


Top
 Profile  
 
 Post subject: Many-to-many RelationShip
PostPosted: Thu May 05, 2005 4:43 am 
Newbie

Joined: Fri Apr 29, 2005 4:58 am
Posts: 12
Location: Chennai INDIA
Let's start by setting up relationships between classes such as User, Roles


Class User contains
email:String
password:String

Class Role contians
name:String
descripition:String


Both the classes USER associated with Roles. A many-to-many relationship exists between Users and Roles (that is, association with independent lifecycles).

User associated with roles Many-to-many Association Unidirectional (Users-->Roles)

[User.java]
/**
* @return
* @hibernate.bag
* table="TBL_JOIN_USER_ROLE"
* cascade="all"
* inverse="true"
*
* @hibernate.collection-key
* column="FK_USER_ID"
*
* @hibernate.collection-many-to-many
* class="net.sf.hibernateExamples.Role"
* column="FK_ROLE_ID"
*
*/
public List getRoles() {
return roles;
}



create table TBL_ROLE (
PK_ROLE_ID BIGINT NOT NULL AUTO_INCREMENT,
VC_DESCRIPTION VARCHAR(200),
VC_NAME VARCHAR(20),
primary key (PK_ROLE_ID)
)

create table TBL_USER (
PK_USER_ID BIGINT NOT NULL AUTO_INCREMENT,
USER_TYPE VARCHAR(255) not null,
FK_GROUP_ID BIGINT,
VC_EMAIL VARCHAR(82) not null unique,
primary key (PK_USER_ID)
)

create table TBL_JOIN_USER_ROLE (
FK_USER_ID BIGINT not null,
FK_ROLE_ID BIGINT not null
)



Rgds
Waltair


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 2:17 pm 
Newbie

Joined: Mon May 02, 2005 3:31 pm
Posts: 4
Yes i know that. That wasn't the question.

Is it possible to give the relation between 2 object an extra propery.
no the objects but the relation.

So the relationschip between user & role gets a relation for example Date (just an example).

Is _that_ possible?

_________________
/~


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 2:22 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
composite element?
or maybe ternary association if you want an entity instead of a 'Date'.
Check the reference guide.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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