-->
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: Loading component properties of a composite-id
PostPosted: Tue Jun 01, 2004 6:03 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
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)
-------------------------------------------------
MpMpo
Code:
<?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>


ManPrev
Code:
<?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>


ManPrevOper
Code:
<?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>


Top
 Profile  
 
 Post subject: Re: Loading component properties of a composite-id
PostPosted: Wed Jun 02, 2004 10:02 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
Does anyone got an idea on this please?
Can't understand the problem...


Top
 Profile  
 
 Post subject: Re: Loading component properties of a composite-id
PostPosted: Thu Jun 17, 2004 10:52 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
Can someone please tell me if this is the proper functioning of Hibernate?

Need to know to clarify my thoughts.

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.  [ 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.