-->
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: Is this the wrong way to map?
PostPosted: Tue Jun 02, 2009 10:01 am 
Newbie

Joined: Tue Jun 02, 2009 9:48 am
Posts: 1
I've got a user/group relationship mapping and i think it might be wrong because the join being created is invalid. anyone have thoughts on this?

tables:
Code:
CREATE TABLE  `SECURITY`.`SEC_GROUP` (
  `GRP_ID` int(10) NOT NULL AUTO_INCREMENT
  PRIMARY KEY (`GRP_ID`),
)

CREATE TABLE  `SECURITY`.`SEC_USER` (
  `SEC_USER_ID` int(10) NOT NULL AUTO_INCREMENT,
)

CREATE TABLE  `SECURITY`.`SEC_USER_GROUP` (
  `USER_GRP_ID` int(10) NOT NULL AUTO_INCREMENT,
  `GRP_ID` int(10) DEFAULT NULL,
  `SEC_USER_ID` int(10) DEFAULT NULL,
  PRIMARY KEY (`USER_GRP_ID`),
  CONSTRAINT `FK_RFRNC_11` FOREIGN KEY (`GRP_ID`) REFERENCES `SEC_GROUP` (`GRP_ID`),
  CONSTRAINT `FK_RFRNC_12` FOREIGN KEY (`SEC_USER_ID`) REFERENCES `SEC_USER` (`SEC_USER_ID`)
)

and they're mapped as:
Code:
<hibernate-mapping package="org"
   schema="HD_SECURITY">
   <class name="User" table="SEC_USER">
      <id name="id" type="int" column="sec_user_id">
         <generator class="increment" />
      </id>
      <one-to-one name="address" class="org.Group"
         cascade="all" lazy="false" property-ref="userid" />
   </class>
</hibernate-mapping>

<hibernate-mapping package="org"
   schema="HD_SECURITY">
   <class name="Group" table="SEC_GROUP">
      <id name="id" type="int" column="grp_id">
         <generator class="increment"/>
      </id>
      <join table="SEC_USER_GROUP">
         <key column="SEC_USER_ID" />
         <property name="userid" column="sec_user_id" />
      </join>
   </class>
</hibernate-mapping>

User is a member of a group. I wanted to just add user id to group from SEC_USER_GROUP and join that mapping to user.

results in this predicate:
Code:
from HD_SECURITY.SEC_USER this_
left outer join HD_SECURITY.SEC_PHONE this_1_ on this_.sec_user_id=this_1_.SEC_USER_ID
left outer join HD_SECURITY.SEC_GROUP group2_ on this_.sec_user_id=group2_.sec_user_id
left outer join HD_SECURITY.SEC_USER_GROUP group2_1_ on group2_.grp_id=group2_1_.SEC_USER_ID where (1=1)

the 2nd outer join is invalid because SEC_USER_ID is on *SEC_USER_GROUP*, not SEC_GROUP as the resulting query suggests.

Is this the wrong way to map it?

Thanks in advance-


Top
 Profile  
 
 Post subject: Re: Is this the wrong way to map?
PostPosted: Wed Jun 03, 2009 11:44 pm 
Newbie

Joined: Mon Apr 06, 2009 9:55 pm
Posts: 12
Hi savantv,

I guess, the problem is that you define one-to-one association in User referring class Group which does not have userid (It does have it only via the join to SEC_USER_GROUP, but I don't thing that this is correct way to accociate).

Why don't you join the SEC_USER_GROUP in User class and then whithin the join define the one-to-one association with Group class?

Something like below (note, the mapping is not tested)

Code:
<hibernate-mapping package="org"
   schema="HD_SECURITY">
   <class name="User" table="SEC_USER">
      <id name="id" type="int" column="sec_user_id">
         <generator class="increment" />
      </id>
                <join table="SEC_USER_GROUP">
                        <key column="SEC_USER_ID" />
                        <one-to-one name="address" class="org.Group"
                  cascade="all" lazy="false"/>
                </join>
   </class>
</hibernate-mapping>

<hibernate-mapping package="org"
   schema="HD_SECURITY">
   <class name="Group" table="SEC_GROUP">
      <id name="id" type="int" column="grp_id">
         <generator class="increment"/>
      </id>
   </class>
</hibernate-mapping>


Hope it helpls.

Regards,
Anton

savantv wrote:
I've got a user/group relationship mapping and i think it might be wrong because the join being created is invalid. anyone have thoughts on this?

tables:
Code:
CREATE TABLE  `SECURITY`.`SEC_GROUP` (
  `GRP_ID` int(10) NOT NULL AUTO_INCREMENT
  PRIMARY KEY (`GRP_ID`),
)

CREATE TABLE  `SECURITY`.`SEC_USER` (
  `SEC_USER_ID` int(10) NOT NULL AUTO_INCREMENT,
)

CREATE TABLE  `SECURITY`.`SEC_USER_GROUP` (
  `USER_GRP_ID` int(10) NOT NULL AUTO_INCREMENT,
  `GRP_ID` int(10) DEFAULT NULL,
  `SEC_USER_ID` int(10) DEFAULT NULL,
  PRIMARY KEY (`USER_GRP_ID`),
  CONSTRAINT `FK_RFRNC_11` FOREIGN KEY (`GRP_ID`) REFERENCES `SEC_GROUP` (`GRP_ID`),
  CONSTRAINT `FK_RFRNC_12` FOREIGN KEY (`SEC_USER_ID`) REFERENCES `SEC_USER` (`SEC_USER_ID`)
)

and they're mapped as:
Code:
<hibernate-mapping package="org"
   schema="HD_SECURITY">
   <class name="User" table="SEC_USER">
      <id name="id" type="int" column="sec_user_id">
         <generator class="increment" />
      </id>
      <one-to-one name="address" class="org.Group"
         cascade="all" lazy="false" property-ref="userid" />
   </class>
</hibernate-mapping>

<hibernate-mapping package="org"
   schema="HD_SECURITY">
   <class name="Group" table="SEC_GROUP">
      <id name="id" type="int" column="grp_id">
         <generator class="increment"/>
      </id>
      <join table="SEC_USER_GROUP">
         <key column="SEC_USER_ID" />
         <property name="userid" column="sec_user_id" />
      </join>
   </class>
</hibernate-mapping>

User is a member of a group. I wanted to just add user id to group from SEC_USER_GROUP and join that mapping to user.

results in this predicate:
Code:
from HD_SECURITY.SEC_USER this_
left outer join HD_SECURITY.SEC_PHONE this_1_ on this_.sec_user_id=this_1_.SEC_USER_ID
left outer join HD_SECURITY.SEC_GROUP group2_ on this_.sec_user_id=group2_.sec_user_id
left outer join HD_SECURITY.SEC_USER_GROUP group2_1_ on group2_.grp_id=group2_1_.SEC_USER_ID where (1=1)

the 2nd outer join is invalid because SEC_USER_ID is on *SEC_USER_GROUP*, not SEC_GROUP as the resulting query suggests.

Is this the wrong way to map it?

Thanks in advance-


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.