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?