-->
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: Composite primary-key with foreign-key
PostPosted: Mon Feb 13, 2006 10:30 am 
Newbie

Joined: Fri Apr 29, 2005 2:35 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.2

Hi people,

I have this tables to map:

Factory(<PK>id, name)
Company(<PK>id, name)
FactoryCompany(<PK><FK>factory_id, <PK><FK>company_id)
AcessUserGroup(<PK><FK>factory_id, <PK><FK>company_id, <PK>id)

So I have an HBM for Factory, 1 for Company, 1 for FactoryCompany and one for AcessUserGroup, but note that FactoryCompany have a composite id called FactoryCompanyPK and the id's are all many-to-one.

In my AcessUserGroup class i have a AcessUserGroupPK that is the Id for AcessUserGroup and it is related to FactoryCompany (the id) how is shown above:

mapped documents:

FactoryCompany.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="package.FactoryCompany"
table="FactoryCompany">

<composite-id name="id"
class="package.FactoryCompanyPK">

<key-many-to-one name="theCompany"
class="package.Company" column="company_id" />

<key-many-to-one name="theFactory"
class="package.Factory"
column="factory_id" />

</composite-id>

<set name="theAccessUserGroup" lazy="true" inverse="true"
cascade="delete" sort="unsorted">

<key>
<column name="company_id" ></column>
<column name="factory_id"></column>
</key>

<one-to-many class="package.AcessUserGroup" />

</set>

</class>

</hibernate-mapping>

AccessUserGroup.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="package.AcessUserGroup"
table="AcessUserGroup"
>

<composite-id
name="id"
class="package.AccessUserGroupPK"
>

<key-many-to-one
name="theFactoryCompany"
class="package.FactoryCompany">
<column name="company_id"></column>
<column name="factory_id"></column>
</key-many-to-one>

<key-property
name="user"
type="java.lang.String"
column="id" />

</composite-id>

</class>

</hibernate-mapping>

My problem is with my queries whith the statement ... AccessUserGroup.id.theFactoryCompany.theFactory.id = :factoryId (for example)...

example:

<query..>
select factory
from package.AccessUserGroup as aug
where aug.id.theFactoryCompany.id.theFactory.id = :factoryId
</query>

queries with statements like that isn't working. If i try the query in my sql client it works, but the objects aren't being populated.

Does anyone have some solution for that?


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.