-->
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: Help with legacy db
PostPosted: Tue May 03, 2005 11:46 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
two tables:
Code:
item {
* id (KEY)
* itemno
* storeid
}

itemdescription {
* id (KEY)
* itemno
* storeid
}



itemno and storeid are a unique pair, identifying an item. For an item I may have a description, identified by the same pair.
I cannot use the "id" key instead of the pair.
itemno and storeid are modeled through a component.

Question: Is there a way to map the one-to-many relationship between item and itemdescription in hibernate 2?
Something like the property-ref attribute but that takes a component or more than one property?

Any suggestion?


Top
 Profile  
 
 Post subject: One-to-Many relationship
PostPosted: Fri May 06, 2005 1:25 am 
Newbie

Joined: Fri Apr 29, 2005 4:58 am
Posts: 12
Location: Chennai INDIA
setting up relationships between classes such as Users, Group


Group Contains
name:String
description:String
User Contains
email:String
password:String

A a one-to-many relationship exists between Groups and Users, since a group has many users. Users can exists outside of a group; that is, aggregation not composition (in database speak no cascade delete relationship exists between Groups and Users).

Group contains User. One-to-many Aggregation Bidirectional (Group<-->Users)


[Group.java]
/**
*
* @return
*
* @hibernate.bag name="users"
* cascade="save-update"
* lazy="true"
* inverse="true"
*
* @hibernate.collection-key
* column="FK_GROUP_ID"
*
* @hibernate.collection-one-to-many
* class="net.sf.hibernateExamples.User"
*/
public List getUsers() {
return users;
}

[User.java]
/**
* @hibernate.many-to-one
* column="FK_GROUP_ID"
* class="net.sf.hibernateExamples.Group"
*/
public Group getGroup() {
return group;
}

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_GROUP (PK_GROUP_ID BIGINT NOT NULL AUTO_INCREMENT,VC_DESCRIPTION VARCHAR(255),VC_NAME VARCHAR(40) unique,primary key (PK_GROUP_ID))

alter table TBL_USER add index (FK_GROUP_ID), add constraint FK_111 foreign key FK_GROUP_ID)
references TBL_GROUP (PK_GROUP_ID)


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.