-->
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: Composite Id
PostPosted: Wed Nov 05, 2003 10:16 am 
Newbie

Joined: Wed Nov 05, 2003 9:54 am
Posts: 2
Hi to everyone, I am new in hibernate and I cant speak english very well, so sorry for any english mistake.
I would really apreciatte if someone could help me!!
I have two classes, one is USER which has name, password, and a list of perfil(which is profile in english i think). and the other one is Perfil(profile) which has the perfil_id, perfil_description attributes.

What I want is, to persist the class USER to a USER table, using the one-to-many, to persist its PERFILS.

and I DO NOT want to persist the class PERFIL, because it has not a reference to USER, in other words, its not bidirecional.

So i want to persist another table tha contains only the PERFIL_ID from class PERFIL, and USER_NAME, from the class USER. this table doesnt camo from a specifc class. istead of that, it uses attributes from 2 diferent classes.

I made two mapping files that are creating the tables well. the way I want, the problem is only with the primary key. It has to be composited of two fields.


/* Table: PERFIL_USUARIO, Owner: SYSDBA */

CREATE TABLE "PERFIL_USUARIO"
(
"ID" INTEGER NOT NULL,
"NOME_USUARIO_FK" VARCHAR(255),
PRIMARY KEY ("ID")
);

I would like that "NOME_USUARIO-FK" was part of the primary key too, and not only "ID"


my mapping files are :


USUARIOPERFIL.HBM.XML :

<?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="com.ipq.usuario.UsuarioPerfil"
table="USUARIO"
proxy="com.ipq.usuario.UsuarioPerfil">
<id name="nome" column="NOME" length="8" >
<generator class="assigned"/>
</id>

<property name="senha" column="SENHA"
not-null="true"/>

<bag name="listaPerfil" inverse="true" lazy="true"
order-by="NOME_USUARIO" cascade="all">
<key column="NOME_USUARIO_FK"/>
<one-to-many class="com.ipq.usuario.Perfil"/>
</bag>
</class>
</hibernate-mapping>


and

PERFIL.HBM.XML

<?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="com.ipq.usuario.Perfil"
table="PERFIL_USUARIO"
dynamic-update="true">

<id name="id" column="ID">
<generator class="assigned"/>
</id>

</class>
</hibernate-mapping>


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.