-->
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.  [ 4 posts ] 
Author Message
 Post subject: Many to one populate foriegn key in class problem
PostPosted: Sun Oct 30, 2005 12:48 am 
Newbie

Joined: Fri Oct 28, 2005 11:49 pm
Posts: 5
HI

Using Hibernate 3.0.5.

I am trying to figure out if this is a problem or if this is done by design.
For the Many-to-one, after executing a query, the many-to-one app_id attribute in AppfObjectVO is NULL.

My question, is this by design, or is there a way to get hibernate to populate that attribute when it's defined as a many to one.


Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true" package="com.cetelex.pwrsecure.dao.vo">
    <class name="AppfObjectVO" table="appf_object">
        <id name="ao_id" type="long" unsaved-value="null">
            <generator class="sequence">
                <param name="sequence">pwrs_seq</param>
            </generator>
        </id>

        <timestamp name="last_chg_dtm"/>

        <many-to-one name="app_code" class="AppVO" column="app_id"  not-null="true" lazy="false"/>
        <many-to-one name="appf_type_code" class="AppfTypeCodeVO" column="ao_atc_id" not-null="true" lazy="false" />

        <property name="ao_class" type="string" not-null="false" length="255"/>
        <property name="last_chg_uid" type="string" length="15" not-null="true"/>

        <set name="racc" inverse="true" lazy="true">
            <key column="ao_id"/>
            <one-to-many class="RaccVO"/>
        </set>
    </class>
</hibernate-mapping>


Class:
Code:
public class AppfObjectVO
{
    private Long                                m_ao_id;
    private Long                                m_app_id;
    private String                              m_ao_class;
    private Long                                m_ao_atc_id;
    private Date                                m_last_chg_dtm;
    private String                              m_last_chg_uid;

    public Long getAo_id()                      {return(m_ao_id);}
    public Long getApp_id()                     {return(m_app_id);}
    public String getAo_class()                 {return(m_ao_class);}
    public Long getAo_atc_id()                  {return(m_ao_atc_id);}
    public Date getLast_chg_dtm()               {return(m_last_chg_dtm);}
    public String getLast_chg_uid()             {return(m_last_chg_uid);}

    public void setAo_id(Long value)            {m_ao_id = value;}
    public void setApp_id(Long value)           {m_app_id = value;}
    public void setAo_class(String value)       {m_ao_class = value;}
    public void setAo_atc_id(Long value)        {m_ao_atc_id = value;}
    public void setLast_chg_dtm(Date value)     {m_last_chg_dtm = value;}
    public void setLast_chg_uid(String value)   {m_last_chg_uid = value;}

    private Set<RaccVO>                         m_racc;
    public Set<RaccVO> getRacc()                {return(m_racc);}
    public void setRacc(Set<RaccVO> v)          {m_racc = v;}

    private AppfTypeCodeVO                          m_appf_type_code;
    public AppfTypeCodeVO getAppf_type_code()       {return(m_appf_type_code);}
    public void setAppf_type_code(AppfTypeCodeVO v) {m_appf_type_code = v;}

    private AppVO                                   m_app_code;
    public AppVO getApp_code()                      {return(m_app_code);}
    public void setApp_code(AppVO v)                {m_app_code = v;}

    public AppfObjectVO() {}
}


SQL:
Code:
String sql = "FROM AppfObjectVO";


SQL Generated by Hibernate:
Code:
select appfobject0_.ao_id as ao1_,
       appfobject0_.last_chg_dtm as last2_7_,
       appfobject0_.app_id as app3_7_,
       appfobject0_.ao_atc_id as ao4_7_,
       appfobject0_.ao_class as ao5_7_,
       appfobject0_.last_chg_uid as last6_7_
       from appf_object appfobject0_

_________________
Thanks,
Brent Parsons


Top
 Profile  
 
 Post subject: Content in database
PostPosted: Sun Oct 30, 2005 4:49 am 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
hej,

The appf_object is populated with non-null data in the app_id column? Realise the question is a bit rudimentary but the many-to-one association looks fine. How about the table corresponding to the AppVO class? Does it contain data mapped by the foreign-key to the appf_object table?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 30, 2005 4:52 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
There's no mapping for field app_id.


Top
 Profile  
 
 Post subject: Re: Content in database
PostPosted: Sun Oct 30, 2005 12:51 pm 
Newbie

Joined: Fri Oct 28, 2005 11:49 pm
Posts: 5
young_matthewd wrote:
hej,

The appf_object is populated with non-null data in the app_id column? Realise the question is a bit rudimentary but the many-to-one association looks fine. How about the table corresponding to the AppVO class? Does it contain data mapped by the foreign-key to the appf_object table?


Hi.

Yes, there is the corresponding attribute in the AppVO.

About it not being mapped, that triggered an idea that I had tried by missed a few options.

On the many-to-on add the update=false and insert=false, and supply
a property for app_id. This solves the problem, and appears to be the way to go. The change also allows you to use the app_id field in SQL as the APP_ID field, not as the name of the many-to-one.

Thanks for both your responses, it was enough to get me thinking about the problem differentl.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true" package="com.cetelex.pwrsecure.dao.vo">
    <class name="AppfObjectVO" table="appf_object">
        <id name="ao_id" type="long" unsaved-value="null">
            <generator class="sequence">
                <param name="sequence">pwrs_seq</param>
            </generator>
        </id>

        <timestamp name="last_chg_dtm"/>

        <many-to-one name="app_code" class="AppVO" column="app_id" insert="false" update="false" not-null="true" lazy="false"/>
        <property name="app_id" type="long" not-null="false"/>

        <many-to-one name="appf_type_code" class="AppfTypeCodeVO" column="ao_atc_id" not-null="true" lazy="false" />

        <property name="ao_class" type="string" not-null="false" length="255"/>
        <property name="last_chg_uid" type="string" length="15" not-null="true"/>

        <set name="racc" inverse="true" lazy="true">
            <key column="ao_id"/>
            <one-to-many class="RaccVO"/>
        </set>
    </class>
</hibernate-mapping>

_________________
Thanks,
Brent Parsons


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.