-->
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: Joining tables to retrieve a non-Entity property
PostPosted: Wed Feb 08, 2006 7:19 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
I am having a problem trying to join a Table within an Entity to retrieve non-Entity property. Let me explain.

I have an Entity, MetaData, which has some 20 properties within one table, Master. Also, there are 6 other properties which are in another Table, Tracker. The two tables have the same primary key, respId. The 6 properties are all non-Entity Objects (Calendar, String, Long, Integer).

When I try to use the @JoinTable annotation no matter what I put as the table or in the @JoinColumns annotation within @JoinTable, Hibernate keeps looking for the properties class name within the Master table (the properties name within the Class is assignedFileNumber; the column that represents it is Tracker.AssignFN; after having Hibernate show me the SQL, it's looking for Master.assignedFileNumber). The only way I can get the right column name is to use the @Column notation after @JoinTable, but then it looks for assignFN within Master, insead of Tracker. If I add the table name to @Column, during the SessionFactory's binding I'm told the table I'm looking for is not available (even though the Entity being bound before MetaData uses Tracker and has no problems). I've also tried using @JoinColumn instead of @JoinTable but the results are the same - I cannot get Hibernate to look in another table for the property.

I'm using Java 1.5.0_6 and Hibernate 3.1.2 with Annotations 3.1b8 to an IBM OS/400 DB2 database. I have checked the documentation for the current release of annotations and all the examples with @JoinTable or @JoinColumns all show either a retrieval of a Collection of Entities, or just a singular Entity. This makes me wonder if what I'm doing is supported yet (even though I can do this with a normal mapping and it would seem getting a non-Entity property would be supported before a Collection of non-Entity properties like is shown in the example on page 33 with the Boy and his Toys) or if I can use the same table for different classes. If someone can point me to the right direction it would be greatly appreciated.

My original (edited) mapping:
Code:
<class name="lig.framework.domain.lead.MetaData" table="Master">
      
    <id name="rId" column="RespId" type="long"/>

...

    <join table="Tracker">
        <key column="RespId"/>
         
        <property name="assignedFileNumber" column="AssignFN" type="integer"/>
        <property name="fdId" column="FDID" type="long"/>
        <property name="receivedDate" column="RcvdDate" type="calendar_date"/>
        <property name="assignedDate" column="AssignDate" type="calendar_date"/>
        <property name="mediaType" column="MediaType" type="string"/>
    </join>      
</class>


MetaData.java (with Annotations)
Code:
@Entity
@org.hibernate.annotations.Entity( mutable=false )
@Table( name="Master" )
public final class MetaData extends LeadImpl
{
    @Transient
    private static final long serialVersionUID = 200512151647l;
   
    @NotNull @Range( min=1, max=99999 )
//    @JoinColumn( table="Tracker", name="rId", referencedColumnName="RespId" )
    @JoinTable( name="Tracker", joinColumns= { @JoinColumn( name="rId", referencedColumnName="respId" ) } )
    @Column( name="AssignFN", insertable=false )
    private Integer assignedFileNumber = null;

...

}


LeadImpl.java (with Annotations)
Code:
@MappedSuperclass
public abstract class LeadImpl implements Lead
{
    private static final long serialVersionUID = 200601261311l;
   
    @Id
    @Column( name="RespId" )
    protected Long rId = null;

...

}


Exception generated if @Column in the code above is commented out (the other 5 properties are annotated with @Transient for the moment)
Code:
Hibernate:
    /* criteria query */ select
        this_.rId as rId2_2_,
        this_.assignedFileNumber as assigned2_2_2_,
        this_.Title as Title2_2_,
        this_.FName as FName2_2_,
        this_.MName as MName2_2_,
        this_.LName as LName2_2_,
        this_.Suffix as Suffix2_2_,
        this_.Addr2 as Addr8_2_2_,
        this_.Addr1 as Addr9_2_2_,
        this_.BadAddr as BadAddr2_2_,
        this_.City as City2_2_,
        this_.State as State2_2_,
        this_.Province as Province2_2_,
        this_.Postal as Postal2_2_,
        this_.County as County2_2_,
        this_.Country as Country2_2_,
        this_.DOB as DOB2_2_,
        this_.Age as Age2_2_,
        this_.Gender as Gender2_2_,
        this_.SSN as SSN2_2_,
        this_.NoCall as NoCall2_2_,
        this_.NoMailCd as NoMailCd2_2_,
        this_.Suppress as Suppress2_2_,
        this_.CustFlag as CustFlag2_2_,
    from
        Master this_
    where
        (
            this_.assignedFileNumber=?
        )
WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: -205, SQLState: 42703
ERROR org.hibernate.util.JDBCExceptionReporter - [SQL0205] Column ASSIGNEDFILENUMBER not in table MASTER in LIG.


btw - I am connecting to 'jdbc:as400://host/LIG' in the Hibernate.cfg.xml file.

Exception generated if @Column in the code above is not commented out (the other 5 properties are annotated with @Transient for the moment)
Code:
    /* criteria query */ select
        this_.rId as rId2_2_,
        this_.AssignFil as AssignFil2_2_,
        this_.Title as Title2_2_,
        this_.FName as FName2_2_,
        this_.MName as MName2_2_,
        this_.LName as LName2_2_,
        this_.Suffix as Suffix2_2_,
        this_.Addr2 as Addr8_2_2_,
        this_.Addr1 as Addr9_2_2_,
        this_.BadAddr as BadAddr2_2_,
        this_.City as City2_2_,
        this_.State as State2_2_,
        this_.Province as Province2_2_,
        this_.Postal as Postal2_2_,
        this_.County as County2_2_,
        this_.Country as Country2_2_,
        this_.DOB as DOB2_2_,
        this_.Age as Age2_2_,
        this_.Gender as Gender2_2_,
        this_.SSN as SSN2_2_,
        this_.NoCall as NoCall2_2_,
        this_.NoMailCd as NoMailCd2_2_,
        this_.Suppress as Suppress2_2_,
        this_.CustFlag as CustFlag2_2_,
    from
        Master this_
    where
        (
            this_.AssignFil=?
        )
WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: -205, SQLState: 42703
ERROR org.hibernate.util.JDBCExceptionReporter - [SQL0205] Column ASSIGNFIL not in table MASTER in LIG.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 9:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use @SecondaryTable, not @JoinTable

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 3:34 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
Yup, that solved it, thanks for the help.


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.