-->
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: Generate an auto id
PostPosted: Thu Feb 03, 2011 4:55 am 
Newbie

Joined: Thu Feb 03, 2011 4:28 am
Posts: 1
Well my problem seams to be easy to solve but i can´t fix it. I´m a newbie on Hibernate programming. I´m in a Seam&Hibernate project and I need to generate an automatic value for an id on my table. I´ve read all Hibernate documentation and nothing of that works for me.

I´m using Hibernate 3.6,Jboss 5.1.0 GA and Postgres9.0 and I´m doing this:

My table script:

CREATE TABLE aisjcrm.zona
(
empresa character varying(4) NOT NULL DEFAULT ''::character varying,
zona character varying(40) NOT NULL DEFAULT ''::character varying,
descripcion character varying(80) NOT NULL DEFAULT ''::character varying,
permitemodificar boolean NOT NULL DEFAULT false,
usr_creacion character varying(40) DEFAULT ''::character varying,
fch_creacion timestamp without time zone,
usr_modif character varying(40) DEFAULT ''::character varying,
fch_modif timestamp without time zone,
id_zona serial NOT NULL, <- That´s the value to generate
CONSTRAINT pk_zona PRIMARY KEY (empresa, zona, id_zona),
CONSTRAINT id_zona UNIQUE (id_zona)
)

My model code:

@GeneratedValue
private int idZona;
...
...
...
@Column(name = "id_zona", nullable = false)
@NotNull
public Integer getIdZona() {
return this.idZona;
}

I also have try this:

@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_GEN")
@javax.persistence.SequenceGenerator(name="SEQ_GEN",sequenceName="my_sequence")

Using any of this examples I always get the same persistence exception: "Batch entry 0 insert into aisjcrm.zona (descripcion, fch_creacion, fch_modif, permitemodificar, usr_creacion, usr_modif, empresa, id_zona, zona) values ('cx', NULL, NULL, '0', NULL, NULL, 'cx', '0', 'cx')" was aborted. Call getNextException to see the cause. This is because hibernate doesn´t generate a value for id_zona and always try to insert a 0 for this field. I´ve check that there isn´t a point on my code where I give a value to id_zona. So I think that the 0 value is generate by Hibernate cause id_zona is an integer or it doesn´t?

¿What do i´m doing wrong? ¿Do i have to write something on any other file to configure it?
¿Is a Hibernate problem or a Seam problem?

Thank you in advance! And sorry for my english.


Top
 Profile  
 
 Post subject: Re: Generate an auto id
PostPosted: Thu Feb 03, 2011 6:18 am 
Newbie

Joined: Sun May 09, 2010 4:48 am
Posts: 11
Try GenerationType.AUTO


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.