-->
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: SchemaExport + AlternativeKey + numeric and other types
PostPosted: Mon Jan 17, 2005 12:53 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
I posted it on Hibernate Users forum but i think is better to post it here.

I got some problems when inserting a new object in database table DESTINOS.
SchemaExport is generating numeric fields , and unique fields
when my database(Sybase) better understands INT and declaring UNIQUE
this way .

create unique index NOME on DESTINOS (
NOME
)



creating a table manually was OK!
create table DESTINOS (

DESTINO_ID INT PRIMARY KEY,
NOME VARCHAR(50) ,
ENDERECO VARCHAR(50) ,
PAIS VARCHAR(50) ,
TELEFONECENTRAL VARCHAR(50) ,
)






What was wrong !?
SchemaExport bug with Sybase?!



There goes de source that is not OK


Hibernate version: 2.1.7

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.Destino" lazy="true" table="DESTINOS">
<id name="id" column="DESTINO_ID" >
<generator class="increment"/>
</id>
<property name="nome" column="NOME" not-null="true" unique="true"/>
<property name="endereco" column="ENDERECO" not-null="true"/>
<property name="pais" column="PAIS" not-null="true"/>
<property name="telefoneCentral" column="TELEFONECENTRAL" not-null="true"/>
<set name="pessoasDestinadas"
cascade="all-delete-orphan"
inverse="true"
lazy="true"
>
<key column ="DESTINO_ID"/>
<one-to-many class="hello.PessoaDestinada"/>
</set>
<set name="ramais" lazy="true" inverse="true" cascade="all" >
<key column="DESTINO_ID"/>
<one-to-many class="hello.Ramal"/>
</set>
<set name="ligacoes" lazy="true" inverse="true" cascade="none">
<key column="DESTINO_ID"/>
<one-to-many class="hello.Ligacao"/>
</set>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
session.save(destino);

Full stack trace of any exception that occurs: Any exceptions occurs

Name and version of the database you are using:Sybase *

The generated SQL (show_sql=true):create table DESTINOS (
DESTINO_ID numeric(19,0) not null,
NOME varchar(255) not null unique,
ENDERECO varchar(255) not null,
PAIS varchar(255) not null,
TELEFONECENTRAL varchar(255) not null,
primary key (DESTINO_ID)
)


Hibernate: insert into DESTINOS (NOME, ENDERECO, PAIS, TELEFONECENTRAL, DESTINO_ID) values (?, ?, ?, ?, ?)

Debug level Hibernate log excerpt:

******************************

Hello all !
I´m new to hibernate and i tried to insert an alternative key on my table DESTINOS.
Hibernate apparently saves it on database , no error is shown.
But it is not saving all fields , just the primary key and the alternative key.


Here goes the code:

Destino destino = new Destino();

destino.setNome("Tramanda Beach");
destino.setPais("Brazil ");
destino.setEndereco("Tramandai ");
destino.setTelefoneCentral("42342");
destino.setRamais(new HashSet());

DestinoDAO dd= new DestinoDAO ();
dd.insertDestino(destino);


In database row i have just these fields persisted

DESTINO_ID NOME ENDERECO PAIS TELEFONECENTRAL
--------------------- ---- -------- ---- ---------------
1 Tramanda Beach



***************



package hello;

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

/**
* @author abarbosa
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/

public class Destino implements Serializable {

/**
* @return Returns the id.
*/
public Long getId() {
return id;
}

/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}

private Long id;

private String nome;

private String endereco;

private String pais;

private String telefoneCentral;

private Set pessoasDestinadas = new HashSet();

private Set ramais = new HashSet();

private Set ligacoes = new HashSet();


public Destino() {
}


public Destino(String nome, String endereco, String pais,
String telefoneCentral,Set pessoasDestinadas,Set ramais) {


setNome(nome);
setEndereco(endereco);
setPais(pais);
setTelefoneCentral(telefoneCentral);
setPessoasDestinadas(pessoasDestinadas);
setRamais(ramais);

}



public void setNome(String nome) {
this.nome = nome;
}

public void setEndereco(String endereco) {
this.endereco = endereco;
}

public void setPais(String pais) {
this.pais = pais;
}

public void setTelefoneCentral(String telefoneCentral) {
this.telefoneCentral = telefoneCentral;
}

public void setPessoasDestinadas(Set pessoasDestinadas) {
this.pessoasDestinadas = pessoasDestinadas;

}

public void setRamais(Set ramais) {

this.ramais = ramais;

}



public void addPessoaDestinada(PessoaDestinada pessoaDestinada) {

if (pessoaDestinada == null)
throw new IllegalArgumentException("Can't add a null pessoasDestinada.");
this.getPessoasDestinadas().add(pessoaDestinada);


}




public String getNome() {
return nome;
}

public String getEndereco() {
return endereco;
}

public String getPais() {
return pais;
}

public String getTelefoneCentral() {
return telefoneCentral;
}

public Set getPessoasDestinadas() {
return pessoasDestinadas;

}

public Set getRamais() {
return ramais;

}

/**
* @param ramal
*/
public void addRamal(Ramal ramal) {
ramal.setDestino(this);
this.getRamais().add(ramal);
// TODO Auto-generated method stub

}


public void addLigacao(Ligacao ligacao) {
ligacao.setDestino(this);
this.ligacoes.add(ligacao);
// TODO Auto-generated method stub

}

/**
* @return Returns the ligacoes.
*/
public Set getLigacoes() {
return ligacoes;
}
/**
* @param ligacoes The ligacoes to set.
*/
public void setLigacoes(Set ligacoes) {
this.ligacoes = ligacoes;
}
}


Thanks for help! (sorry by 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.