I'm using Hibernate 2.1.3
MpMpo has a composite-id of
ManPrev and
ManPrevOper.
I'm trying to load an instance of
MpMpo.
My problem is after loading a
MpMpo, all properties of
ManPrev and
ManPrevOper come
null except for their id's!
Example:
After the executing the method code below:
Code:
System.out.println("MAN_PREV_ID: " + mp_mpo.getComp_id().getManPrev().getId());
System.out.println("MAN_PREV_REF: " + mp_mpo.getComp_id().getManPrev().getReferencia());
System.out.println("MAN_PREV_OPER_ID: " + mp_mpo.getComp_id().getManPrevOper().getId());
System.out.println("MAN_PREV_OPER_REF: " + mp_mpo.getComp_id().getManPrevOper().getReferencia());
Console:
MAN_PREV_ID: 1
MAN_PREV_REF: null
MAN_PREV_OPER_ID: 1
MAN_PREV_OPER_REF: null
Please, I would like to know if it is possible and how can I return all properties of both
ManPrev and
ManPrevOper which are the components of
MpMpo composite-id, by doing a
session.get on
MpMpo?
-------------------
Method code
-------------------
The code is very simple as follows:
Code:
( ... )
MpMpoPK mp_mpo_pk = new MpMpoPK();
ManPrev man_prev = new ManPrev();
man_prev.setId(new Long(1));
mp_mpo_pk.setManPrev(man_prev);
ManPrevOper man_prev_oper = new ManPrevOper();
man_prev_oper.setId(new Long(1));
mp_mpo_pk.setManPrevOper(man_prev_oper);
MpMpo mp_mpo = (MpMpo)session.get(MpMpo.class, mp_mpo_pk);
( ... )
-------------------
Table structure
-------------------
Code:
mp_mpo (PK: man_prev_fk,man_prev_oper_fk)
|
|---> man_prev (PK: id)
|
|---> man_prev_oper (PK:id)
-------------------------------------------------
Mapping files (created with Middlegen)
-------------------------------------------------
MpMpoCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="vo.MpMpo"
table="mp_mpo"
>
<composite-id name="comp_id" class="vo.MpMpoPK">
<!-- bi-directional many-to-one association to ManPrevOper -->
<key-many-to-one
name="manPrevOper"
class="vo.ManPrevOper"
>
<column name="man_prev_oper_fk" />
</key-many-to-one>
<!-- bi-directional many-to-one association to ManPrev -->
<key-many-to-one
name="manPrev"
class="vo.ManPrev"
>
<column name="man_prev_fk" />
</key-many-to-one>
</composite-id>
<property
name="periodicidade"
type="int"
column="periodicidade"
not-null="true"
length="4"
/>
</class>
</hibernate-mapping>
ManPrevCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="vo.ManPrev"
table="man_prev"
>
<id
name="id"
type="long"
column="id"
>
<generator class="sequence">
<param name="sequence">man_prev_seq</param>
</generator>
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to MpMpo -->
<set
name="mpMpos"
lazy="true"
inverse="true"
>
<key>
<column name="man_prev_fk" />
</key>
<one-to-many
class="vo.MpMpo"
/>
</set>
</class>
</hibernate-mapping>
ManPrevOperCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="vo.ManPrevOper"
table="man_prev_oper"
>
<id
name="id"
type="long"
column="id"
>
<generator class="sequence">
<param name="sequence">man_prev_oper_seq</param>
</generator>
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to MpMpo -->
<set
name="mpMpos"
lazy="true"
inverse="true"
>
<key>
<column name="man_prev_oper_fk" />
</key>
<one-to-many
class="vo.MpMpo"
/>
</set>
</class>
</hibernate-mapping>