-->
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.  [ 3 posts ] 
Author Message
 Post subject: Identity Column with HSQL
PostPosted: Sat Jul 21, 2007 9:50 pm 
Newbie

Joined: Thu Jul 12, 2007 9:27 pm
Posts: 11
I have a data object, Person, which stores the first and last name of a person. It also has a field, long id. This ID should be auto-incremented by the DB when a person is inserted into the database, but it doesn't seem to be happening. Details below...

Hibernate version: 3

Name and version of the database you are using: HSQL

CREATE TABLE PEOPLE (PERSON_ID bigint IDENTITY, ....)

@Entity
@Table(name = "PEOPLE")
class Person {
@Id
@Column(name="PERSON_ID")
long id;

.....
}

everytime I save a Person the ID is set to 0, so I only end up with one object in the DB. Am I missing something? I should just be able to save it and the ID be incremented automatically right?

Person p = createPerson();
session.save(p);

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 21, 2007 10:13 pm 
Newbie

Joined: Thu Jul 12, 2007 9:27 pm
Posts: 11
so I added the "Generated" annotation...

@Entity
@Table(name = "PEOPLE")
class Person {
@Id
@Column(name="PERSON_ID")
@Generated(value = GenerationTime.INSERT)
long id;

.....
}

but that doesn't seem to change anything


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 21, 2007 10:18 pm 
Newbie

Joined: Thu Jul 12, 2007 9:27 pm
Posts: 11
Looks like I needed some more...

@Generated(value = GenerationTime.INSERT)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="IdGenerator")
@SequenceGenerator(initialValue=0, name="IdGenerator")


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