-->
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: nested composite-id mapping and many-to-many relations
PostPosted: Mon Nov 20, 2006 6:13 pm 
Newbie

Joined: Mon Nov 20, 2006 4:48 pm
Posts: 1
Location: Buenos Aires
Hi all,

I need help to map some legacy DB tables.

Here they are:

- A table with a list of transactions with composite primary key.
tb_transaccion (class cgTransaccion)
pk cod_trans
pk condicion
descripcion

- A table with a list of groups of grantors
tb_grupos_autorizacion (class cgGrupoAutorizacion)
pk cod_grupo_aut
description

and a relation table to resolve the questions
- which groups can do some specific transaction?
- which transactions can some specific group?
this is a many-to-many relation table.

tb_grupo_transaccion (class cgGrupoTransaccion)
pk cod_grupo_aut
pk cod_trans
pk condicion

I defined two components to encapsulate the primary keys
of tb_transaccion and tb_grupo_transaccion
----------------------------------------------------------
[code]
package cg.java.Comun;
import java.io.Serializable;
public class pkTransaccion implements Serializable {
String cod_trans="";
String condicion="";

public pkTransaccion() {
this.cod_trans = null;
this.condicion = null; }

public pkTransaccion(String Cod_trans, String Condicion) {
this.cod_trans = Cod_trans;
this.condicion = Condicion; }

public String getCod_trans() { return cod_trans; }
public void setCod_trans(String cod_trans) { this.cod_trans = cod_trans; }
public String getCondicion() { return condicion; }
public void setCondicion(String condicion) { this.condicion = condicion; }
}
[/code]
----------------------------------------------------------
[code]
package cg.java.Comun;
import java.io.Serializable;
public class pkGrupoTransaccion implements Serializable{

int cod_grupo_aut=0;
pkTransaccion trx_id = new pkTransaccion();

public pkGrupoTransaccion() {
this.cod_grupo_aut = 0;
this.trx_id.setCod_trans(null);
this.trx_id.setCondicion(null);
}
public pkGrupoTransaccion(int CodGrupoAut, Transaccion Trx) {
this.cod_grupo_aut = CodGrupoAut;
this.trx_id.setCod_trans(Trx.getCod_trans());
this.trx_id.setCondicion(Trx.getCondicion());
}

public int getCod_grupo_aut() { return cod_grupo_aut; }
public void setCod_grupo_aut(int cod_grupo_aut) { this.cod_grupo_aut = cod_grupo_aut; }
public Transaccion getTrx_id() { return trx_id; }
public void setTrx_id(Transaccion trx_id) { this.trx_id = trx_id; }
}
[/code]
----------------------------------------------------------

so this is the hbm for tb_transaccion
[code]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cg.java.Comun">
<class name="cgTransaccion" table="tb_transaccion">
<composite-id name="id" class="pkTransaccion">
<key-property name="cod_trans" type="string" column="cod_trans" length="7"/>
<key-property name="condicion" type="string" column="condicion" length="15"/>
</composite-id>
<property name="descripcion" type="string" length="100"/>
</class>
</hibernate-mapping>
[/code]

and the hbm for tb_grupos_autorizacion

[code]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cg.java.Comun">
<class name="cgGrupoAutorizacion" table="tb_grupos_autorizacion">
<id name="id" column="cod_grupo_aut" type="string"/>
<property name="descripcion" type="string" length="100"/>
<property name="nivel" type="integer"/>
</class>
</hibernate-mapping>
[code]

so far so good, here are the questions:

How can I make the hbm for cgtb_grupo_transaccion?

this is my version

[code]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cg.java.Comun">
<class name="cgGrupoTransaccion" table="cgtb_grupo_transaccion">
<composite-id name="id" class="pkGrupoTransaccion">
<key-property name="cod_grupo_aut"/>
<key-property name="cod_trans"/>
<key-property name="condicion"/>
</composite-id>
</class>
</hibernate-mapping>
[/code]

but the compiler complains about "field [cod_trans] not found on cg.java.Comun.pkGrupoTransaccion"

Please look at the components, pkGrupoAutorizacion has two properties,

int cod_grupo_aut
pkTransaccion trx_id = new pkTransaccion();

How this is supossed to be mapped into the hbm?

and most important

How do I make the relations between the tables?


TIA
Pablo

ps. sorry for the extension. (and my english)


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.