-->
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.  [ 5 posts ] 
Author Message
 Post subject: accessing one column of a mapped composite-id
PostPosted: Mon Sep 06, 2004 6:58 am 
Beginner
Beginner

Joined: Sun Aug 01, 2004 5:16 am
Posts: 22
Location: BERLIN
e.g:

/**
*@hibernate.class
* table="table_in_database"
* schema="tables_schema"
*/
class table implements Serializable{

public table_pk table;

public table(){
super();
}

/**
* @hibernate.id
* class="<code>table_pk</code>";
*/
public table_pk getTable(){
return table;
}

public setTable(String table){
this.table=table;
}
}

class table_pk implements Serializable{

public long column1;
public String column2;
/**
*@hibernate.property
* column="column1_in_table"
*/
public long getColumn1(){return column1;}
/**
*@hibernate.property
* column="column2_in_table"
*/
public String getColumn2(){return column2;}

public void setColumn1(long column1){this.column1=column1;}
public void setColumn2(String column2){this.column2=column2;}

//overriden functions
public boolean equals(){//overriden};
public int hashCode(){//overriden};
}

how can i now manage to get access to one column of the composite-id,
to initiate another e.g: many-to-one mapping with one of these column...
any idea thx.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 11:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
table.getTable().getColumn1()

But in you case, unsing <many-to-one column="column1_in_table" insert="false" undate="false"/>
Will do the trick

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 3:06 am 
Beginner
Beginner

Joined: Sun Aug 01, 2004 5:16 am
Posts: 22
Location: BERLIN
ok, thx...but now lets go further..:

From the above Classes XDoclet generates me this MappingFile:


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="package.path.table"
        table="table_in_database"
        schema="tables_schema">
        <composite-id
            name="t_pk"
            class="package.path.table_pk">
                     <key-property
                        name="ker"
                        type="long"
                        column="column1_in_table"
                        length="4"/>
                    <key-many-to-one
                        name="land"
                        class="package.path.ClassOfReferencedTable"
                        column="column2_in_table"/>
        </composite-id>
    </class>
</hibernate-mapping>

now i try to get acces over follwing mapped Class:
Code:
class table_2 {
public long column1;
public table column2;
[color=blue]/**
*@hibernate.id
* column="column1_in_table2"
* generator-class="assigned"
*/ [/color]
public long getColumn1(){return column1;}
[color=blue]/**
* @hibernate.many-to-one         
* column = "column2_in_table2"
* not-null = "true"
* property-ref="column1_in_table"//should i use this?
* class="<code>table</code>";
*/[/color]public String getColumn2(){return column2;}
[color=blue]/**
* @hibernate.many-to-one         
* column = "column3_in_table2"
* not-null = "true"
* class="<code>anothertable</code>";
*/[/color]
public String getColumn2(){return column2;}
public void setColumn1(long column1){this.column1=column1;}
public void setColumn2(table column2){this.column2=column2;}
public void setColumn2(anothertable column3){this.column2=column3;}
public String toString(){
//get all fields and concat them to one String;
}
}

now, executing this:
Code:
table2 t2=(table2)Session.get(table2.class);
System.out.println(t2);

throws following:
Code:
net.sf.hibernate.MappingException:
Foreign key (table2[column1_in_table2]))
must have same number of columns as the referenced primary key (table [column1,column2])

you still can follow me...?

by using update="false" and insert="false" in the XDoclet-tag of the second Method ,Hibernate says that that (update + insert) are not
supported buy that component....

still any idea my friend, thx....im near going crying....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 11:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You're not showing me the right mapping.
Thre should be somewhere a link (many-to-oone) from table2 to table and the many-to-one must look like
Code:
<many-to-one>
  <column name="name-of-column-for-1st-pk-column-of-table"/>
  <column name="name-of-column-for-2nd-pk-column-of-table"/>
</many-to-one>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 6:04 am 
Beginner
Beginner

Joined: Sun Aug 01, 2004 5:16 am
Posts: 22
Location: BERLIN
thanx for answering.
thats the problem,
i m trying to link in a many-to-one relation

from table_2 to table only one column of the primary key...


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