-->
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: Insert Object in Table, with a PK without auto-increment
PostPosted: Sat Aug 20, 2005 8:31 pm 
Newbie

Joined: Fri Aug 19, 2005 10:23 pm
Posts: 4
Location: Belem - ParĂ¡ - Brazil
Hello,

I'm trying to insert a register in my database MySQL, using Hibernate Annotations.
I'm using this class:


@Entity
@Table(name="grupo")
public class Grupo {
private int codGrupo;
private String descricao;

@Column(name="descricao",nullable=false,unique=true)
public String getDescricao() {
return this.descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}

@Id(generate=GeneratorType.NONE)
@Column(name="codgrupo")
public int getCodGrupo() {
return codGrupo;
}
public void setCodGrupo(int codGrupo) {
this.codGrupo = codGrupo;
}

}


and this code in my Unit Test:


public void testInserir(){
Grupo g = new Grupo();
g.setCodGrupo(1);
g.setBanco("teste");
this.facade.inserir(g);
}


and the "inserir" method in facade use: getHibernateTemplate().save(g);

*** I'm using Hibernate+Spring

The register doesn't record in my database.
But, when I use @Id(generate=GeneratorType.IDENTITY), the register is recorded.

Somebody know as to decide this?

Thanks.

_________________
Breno Barros
Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 8:40 pm 
Newbie

Joined: Fri Aug 19, 2005 10:23 pm
Posts: 4
Location: Belem - ParĂ¡ - Brazil
to rectify:

in unit test, the correct code is:

public void testInserir(){
Grupo g = new Grupo();
g.setCodGrupo(1);
g.setDescricao("teste");
this.facade.inserir(g);
}

_________________
Breno Barros
Software Engineer


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.