-->
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: Need help on Foriegn Key Relationship
PostPosted: Tue May 15, 2007 9:13 am 
Newbie

Joined: Tue May 15, 2007 9:01 am
Posts: 2
Hi,
I have two tables user and realm with the below mentioned structures

Realm Table

create table REALM (ur_id INT(18) NOT NULL AUTO_INCREMENT,ur_name varchar(200) UNIQUE NOT NULL, PRIMARY KEY (ur_id));



User Table

Create table USER (usr_id INT(18) NOT NULL AUTO_INCREMENT,usr_user_id varchar(200) UNIQUE NOT NULL,usr_urlm_id INT(18) PRIMARY KEY (usr_id));


alter table USER add constraint usersFK0 foreign key (usr_urlm_id ) references SEC_USER_REALM (ur_id)

It is a simple web based app,lication which uses mysql as the database

When we create the user with this structure, we get the realm name and user name as a string from the GUI where as the prioary keys are integer s as the primary key fields are auto generated

My question is how do u model them using the hibernate mapping file ..

the following are the corresponding mapping files





[code]

Realm.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.comverse.rtbd.security.dbaccess.IdentityManagement.UserRealm" table="REALM">
<id name="urId" column="UR_ID" type="int">
<generator class="assigned" />
</id>
<property name="urName" column="ur_name" type="string" not-null="true" />
<set name="users" cascade="all-delete-orphan" lazy="true" inverse="true">
<key column="usr_urlm_id" />
<one-to-many class="com.comverse.rtbd.security.dbaccess.IdentityManagement.User" />
</set>

</class>
</hibernate-mapping>


User.hbm.xml


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.comverse.rtbd.security.dbaccess.IdentityManagement.User" table="sec_ccbs_user">
<id name="usrId" column="usr_id" type="int">
<generator class="assigned" />
</id>
<property name="usrUrlmId" column="usr_urlm_id" not-null="true" />
<property name="usrUserId" column="usr_user_id" type="string" not-null="true" />
<many-to-one name="usrUrlmId" column="usr_urlm_id" class="com.comverse.rtbd.security.dbaccess.IdentityManagement.UserRealm" cascade="save-update" />
</class>
</hibernate-mapping>

However, i always get a exception the Inavlis argumemnt exception when i execute the same .Please help me in solving this bug




[/code]


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.