-->
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.  [ 3 posts ] 
Author Message
 Post subject: in one to may, mapping non primary key as foreign key(need )
PostPosted: Fri Jun 13, 2008 4:14 am 
Newbie

Joined: Fri Jun 13, 2008 4:00 am
Posts: 2
i have two hbm files

Group.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.khushiiit.domain.Group" table="GROUP_TABLE">
<id name="id" column="GROUP_ID" unsaved-value="0">
<generator class="increment"></generator>
</id>
<property name="groupName" type="string" column="GROUP_NAME" not-null="true"></property>
<property name="mobiles" type="string" column="MOBILES"></property>

</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.khushiiit.domain.User" table="USER_TABLE">

<id name="name" type="string" column = "USER_NAME"></id>
<property name="passwd" type="string" column="PASSWORD" not-null="true"> </property>
<property name="balance" type="double" column = "BALANCE"></property>
<list name="userGroups" cascade="all, delete-orphan">
<key column="user_id" />
<list-index/>
<one-to-many class="com.khushiiit.domain.Group" />
</list>
</class>

</hibernate-mapping>


I want that corresponding to each user there is no repeating group.
like A and B are user
than A and B may contain group with same name but
A can have two groups with same name ..


waiting for response ......................


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 10:11 am 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
could u explain this again..

>I want that corresponding to each user there is no repeating group.
>like A and B are user
>than A and B may contain group with same name but
> A can have two groups with same name ..

I am assuming that you are asking for this..

>than A and B may contain group with same name but
> A can't have two groups with same name ..

i.e Each user can have unique group names with in their contexts.

Actually I too is looking for such solution using annotations.. For now, I am checking for such constrains in my code while saving each user.

Regards,
Nagendra

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


Top
 Profile  
 
 Post subject: reply
PostPosted: Sat Jun 14, 2008 4:36 pm 
Newbie

Joined: Fri Jun 13, 2008 4:00 am
Posts: 2
Sorry for Misspelled and thanks for correcting me.

This is exactly what i want to ask.

actually i am also using constraints to bypass the situation in which one user have two similar group.


This problem can be solved in one way if we replace one to many mapping from User to many to one in Group class and use property-ref to describer group name as foreign key but i dont want to do this coz in my code a group exist because of user but not like user exist coz of group.....



looking for more solutions .....................


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