-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help Mapping ORM
PostPosted: Fri Aug 05, 2005 3:45 pm 
Newbie

Joined: Fri Aug 05, 2005 3:42 pm
Posts: 12
Hi!

I'm working with Hibernate and i dont know how to map a class. I'll post the class, the SQL and the Mapping.hbm.xml i've created. If there's somebody who could help me i'll thank a LOT!

Under here is the SQL

---------------------------------------------------------------------------------------------

CREATE TABLE `projeto` (
`ID_PROJETO` int(11) NOT NULL auto_increment,
`ID_TIPO_SITUACAO_PROJETO` int(11) NOT NULL default '0',
`VERSAO` varchar(10) default NULL,
`SIGLA` varchar(15) default NULL,
`NOME_PROJETO` varchar(200) default NULL,
`DESCRICAO` text,
`DATA_INICIO` date default NULL,
`DATA_FIM_PREVISTO` date default NULL,
`DATA_FIM_REAL` date default NULL,
PRIMARY KEY (`ID_PROJETO`),
KEY `PROJETO_FKIndex1` (`ID_TIPO_SITUACAO_PROJETO`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Now i'm posting the class code

-------------------------------------------------------------------------------------------
package com.transfer.object;

import java.util.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
* @version 1.0
* @created 02-mai-2005 18:12:55
* @Classe de um grupo;
*/
public class GrupoTO implements Serializable{

private long idGrupo; //Hash de um grupo
private long idGrupoFilho; //Hash do grupo filho
private String nomeDoGrupo; //String nome do grupo
private String nivel; //Nível de identação
private Set listaDeFilhos; //Lista de filhos do objeto

//Construtor da classe
public GrupoTO(){
this.listaDeFilhos = new HashSet();
}
public void setListaDeFilhos(Set lista){
this.listaDeFilhos = lista;
}
public Set getListaDeFilhos(){
return this.listaDeFilhos;
}
public void setNivel(String umNivel){
this.nivel = umNivel;
}
public String getNivel(){
return this.nivel;
}
//Seta o Id Grupo
public void setIdGrupo(long id){
this.idGrupo = id;
}
//Retorna o id do grupo
public long getIdGrupo(){
return this.idGrupo;
}
//Seta o id do grupo filho.
public void setIdGrupoPai(long id){
this.idGrupoFilho = id;
}
//Retorna o id do grupo filho
public long getIdGrupoPai(){
return this.idGrupoFilho;
}
//Seta o nome do grupo
public void setNomeDoGrupo(String umNomeGrupo){
this.nomeDoGrupo = umNomeGrupo;
}
//Retorna o nome do grupo
public String getNomeDoGrupo(){
return this.nomeDoGrupo;
}
//Zera o bichinho.
public void finalize() throws Throwable {
this.idGrupo = 0;
this.idGrupoFilho = 0;
this.nomeDoGrupo = null;
}
}

And now the GrupoTO.hbm.xml.

-------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<!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.transfer.object.GrupoTO" table="grupo">
<id name="idGrupo" column="id_grupo" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="nomeDoGrupo" type="java.lang.String" column="descricao" length="255" not-null="true"/>
<property name="nivel" type="java.lang.String" column="nivel" length="2" not-null="true"/>
<set name="listaDeFilhos" lazy="true" inverse="true">
<key column="id_grupo_superior"/>
<many-to-one class="com.transfer.object.GrupoTO"/>
</set>
</class>
</hibernate-mapping>

Well the model and the business rule says that every 'grupo' line has a father that is represented by the column id_grupo_superior.
In the class model every 'grupo' object has a Set o sons.

Finally the mapping file is there and i really don't know how the make this, so every help will be welcome!

Thanks a lot!

[]'s
[size=18]
[/size]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 3:47 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 10:27 am
Posts: 23
Please don't make your question in such a large font. It's very troublesome to read.

_________________
- Richard Burton


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