-->
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.  [ 1 post ] 
Author Message
 Post subject: Collection doesnt work
PostPosted: Mon Apr 18, 2005 6:27 pm 
Newbie

Joined: Mon Apr 18, 2005 5:53 pm
Posts: 6
Hibernate version:3.0

My database have this relationships:
A table named "Item". The primary key is (cod_empresa, cod_item)
A table named "Estrutura". The primary key is
(cod_empresa, cod_item_pai, cod_item_filho)
I have two foreign keys for "estrutura":
estrutura (cod_empresa, cod_item_pai) -> item (cod_empresa, cod_item)
estrutura (cod_empresa, cod_item_compon) -> item (cod_empresa, cod_item)

This means that an "Item" has a collection os "Estrutura"

Item ----------> estrutura
1.. ..N

I made these mapping for both classes:

Item map:
<hibernate-mapping>
<class name="imb.fabrica.database.Item" table="item" mutable="false">
<composite-id>
<key-property name="codEmpresa" column="cod_empresa"/>
<key-property name="codItem" column="cod_item"/>
</composite-id>

<set name="estrutura" table="estrutura">
<key>
<column name="cod_empresa"/>
<column name="cod_item_pai"/>
</key>
<one-to-many class="imb.fabrica.database.Estrutura"/>
</set>
</class>
</hibernate-mapping>


Estrutura map:

<hibernate-mapping>
<class name="imb.fabrica.database.Estrutura" table="estrutura" mutable="false">
<composite-id>
<key-property name="codEmpresa" column="cod_empresa"/>
<key-property name="codItemPai" column="cod_item_pai"/>
<key-property name="codItemCompon" column="cod_item_compon"/>
</composite-id>

<many-to-one name="itemPai" class="imb.fabrica.database.Item" insert="false" update="false">
<column name="cod_empresa"/>
<column name="cod_item_pai"/>
</many-to-one>

<many-to-one name="itemFilho" class="imb.fabrica.database.Item" insert="false" update="false">
<column name="cod_empresa"/>
<column name="cod_item_compon"/>
</many-to-one>

</class>

</hibernate-mapping>


when I try to execute the following code,
the iterator doenst print any son! The method getCodItemCompon()
returns an empty collection. Why???
:

Item i = new Item("01", "7210971992");

i = (Item) session.get(Item.class, i);

for (Estrutura e: i.getEstrutura()){
System.out.println("son: " + e.getCodItemCompon());
}

Item.java:

package imb.fabrica.database;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;


public class Item implements Serializable{
private String codEmpresa;
private String codItem;

private Collection<Estrutura> estrutura = new HashSet<Estrutura>();


public Item(){

}

public Item(String codEmpresa, String codItem){
super();
this.codEmpresa = codEmpresa;
this.codItem = codItem;
}


public String getCodEmpresa() {
return codEmpresa;
}

public void setCodEmpresa(String codEmpresa) {
this.codEmpresa = codEmpresa;
}

public String getCodItem() {
return codItem;
}

public void setCodItem(String codItem) {
this.codItem = codItem;
}

public Collection<Estrutura> getEstrutura() {
return estrutura;
}

public void setEstrutura(Collection<Estrutura> estrutura) {
this.estrutura = estrutura;
}
}

Estrutura.java:

package imb.fabrica.database;

import java.io.Serializable;


public class Estrutura implements Serializable{

private String codEmpresa;
private String codItemPai;
private String codItemCompon;

private Item itemPai;
private Item itemFilho;
private Double quantidade;

public Estrutura(){

}

public Item getItemFilho() {
return itemFilho;
}

public void setItemFilho(Item itemFilho) {
this.itemFilho = itemFilho;
}

public Item getItemPai() {
return itemPai;
}

public void setItemPai(Item itemPai) {
this.itemPai = itemPai;
}

public Double getQuantidade() {
return quantidade;
}

public void setQuantidade(Double quantidade) {
this.quantidade = quantidade;
}

public String getCodEmpresa() {
return codEmpresa;
}

public void setCodEmpresa(String codEmpresa) {
this.codEmpresa = codEmpresa;
}

public String getCodItemCompon() {
return codItemCompon;
}

public void setCodItemCompon(String codItemCompon) {
this.codItemCompon = codItemCompon;
}

public String getCodItemPai() {
return codItemPai;
}

public void setCodItemPai(String codItemPai) {
this.codItemPai = codItemPai;
}
}


Debug level Hibernate log excerpt:
19:28:54,828 DEBUG SQL:292 - select item0_.cod_empresa as cod1_0_, item0_.cod_item as cod2_0_ from item item0_ where item0_.cod_empresa=? and item0_.cod_item=?
Hibernate: select item0_.cod_empresa as cod1_0_, item0_.cod_item as cod2_0_ from item item0_ where item0_.cod_empresa=? and item0_.cod_item=?
19:28:54,828 DEBUG AbstractBatcher:343 - preparing statement
19:28:54,843 DEBUG StringType:59 - binding '01' to parameter: 1
19:28:54,843 DEBUG StringType:59 - binding '7210971992' to parameter: 2
19:28:54,843 DEBUG AbstractBatcher:274 - about to open ResultSet (open ResultSets: 0, globally: 0)
19:28:54,843 DEBUG AbstractBatcher:281 - about to close ResultSet (open ResultSets: 1, globally: 1)
19:28:54,859 DEBUG AbstractBatcher:266 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
19:28:54,859 DEBUG AbstractBatcher:363 - closing statement
19:28:54,890 DEBUG AbstractBatcher:258 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
19:28:54,890 DEBUG SQL:292 - select estrutura0_.cod_empresa as cod1___, estrutura0_.cod_item_pai as cod2___, estrutura0_.cod_item_compon as cod3___, estrutura0_.cod_empresa as cod1_0_, estrutura0_.cod_item_pai as cod2_0_, estrutura0_.cod_item_compon as cod3_0_, estrutura0_.cod_empresa as cod1_37_0_, estrutura0_.cod_item_pai as cod2_37_0_, estrutura0_.cod_item_compon as cod3_37_0_ from estrutura estrutura0_ where estrutura0_.cod_empresa=? and estrutura0_.cod_item_pai=?
Hibernate: select estrutura0_.cod_empresa as cod1___, estrutura0_.cod_item_pai as cod2___, estrutura0_.cod_item_compon as cod3___, estrutura0_.cod_empresa as cod1_0_, estrutura0_.cod_item_pai as cod2_0_, estrutura0_.cod_item_compon as cod3_0_, estrutura0_.cod_empresa as cod1_37_0_, estrutura0_.cod_item_pai as cod2_37_0_, estrutura0_.cod_item_compon as cod3_37_0_ from estrutura estrutura0_ where estrutura0_.cod_empresa=? and estrutura0_.cod_item_pai=?
19:28:54,890 DEBUG AbstractBatcher:343 - preparing statement
19:28:54,890 DEBUG StringType:59 - binding '01' to parameter: 1
19:28:54,890 DEBUG StringType:59 - binding '7210971992' to parameter: 2
19:28:54,890 DEBUG AbstractBatcher:274 - about to open ResultSet (open ResultSets: 0, globally: 0)
19:28:54,890 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,890 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,906 DEBUG StringType:86 - returning '500017 ' as column: cod3_0_
19:28:54,906 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,906 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:54,906 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,906 DEBUG StringType:86 - returning '500017 ' as column: cod3_37_0_
19:28:54,906 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,906 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,906 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,906 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,906 DEBUG StringType:86 - returning '500017 ' as column: cod3___
19:28:54,906 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,906 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,906 DEBUG StringType:86 - returning '500115 ' as column: cod3_0_
19:28:54,906 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,921 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:54,921 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,921 DEBUG StringType:86 - returning '500115 ' as column: cod3_37_0_
19:28:54,921 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,921 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,921 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,921 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,921 DEBUG StringType:86 - returning '500115 ' as column: cod3___
19:28:54,921 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,921 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,921 DEBUG StringType:86 - returning '500118 ' as column: cod3_0_
19:28:54,921 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,921 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:54,921 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,937 DEBUG StringType:86 - returning '500118 ' as column: cod3_37_0_
19:28:54,937 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,937 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,937 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,937 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,937 DEBUG StringType:86 - returning '500118 ' as column: cod3___
19:28:54,937 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,937 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,937 DEBUG StringType:86 - returning '503379 ' as column: cod3_0_
19:28:54,937 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,937 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:54,937 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,937 DEBUG StringType:86 - returning '503379 ' as column: cod3_37_0_
19:28:54,937 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,937 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,953 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,953 DEBUG StringType:86 - returning '503379 ' as column: cod3___
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,953 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,953 DEBUG StringType:86 - returning '503432 ' as column: cod3_0_
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,953 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,953 DEBUG StringType:86 - returning '503432 ' as column: cod3_37_0_
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,953 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,953 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,953 DEBUG StringType:86 - returning '503432 ' as column: cod3___
19:28:54,953 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,968 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,968 DEBUG StringType:86 - returning '503548 ' as column: cod3_0_
19:28:54,968 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,984 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:54,984 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,984 DEBUG StringType:86 - returning '503548 ' as column: cod3_37_0_
19:28:54,984 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,984 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,984 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:54,984 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:54,984 DEBUG StringType:86 - returning '503548 ' as column: cod3___
19:28:54,984 DEBUG StringType:86 - returning '01' as column: cod1_0_
19:28:54,984 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_0_
19:28:54,984 DEBUG StringType:86 - returning '7210971992T ' as column: cod3_0_
19:28:54,984 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:54,984 DEBUG StringType:86 - returning '7210971992 ' as column: cod2_37_0_
19:28:55,000 DEBUG StringType:86 - returning '01' as column: cod1_37_0_
19:28:55,000 DEBUG StringType:86 - returning '7210971992T ' as column: cod3_37_0_
19:28:55,000 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:55,000 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:55,000 DEBUG StringType:86 - returning '01' as column: cod1___
19:28:55,000 DEBUG StringType:86 - returning '7210971992 ' as column: cod2___
19:28:55,000 DEBUG StringType:86 - returning '7210971992T ' as column: cod3___
19:28:55,000 DEBUG AbstractBatcher:281 - about to close ResultSet (open ResultSets: 1, globally: 1)
19:28:55,000 DEBUG AbstractBatcher:266 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
19:28:55,000 DEBUG AbstractBatcher:363 - closing statement


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.