-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate generated id's
PostPosted: Mon Dec 18, 2006 4:31 pm 
Newbie

Joined: Mon Dec 18, 2006 4:14 pm
Posts: 3
Hibernate version:3.2

Hi

I am running a couple of JUnit tests to try out Hibernate Annotations but the generated ID's for my database inserts never reset. I can insert a row, then delete it from the database and when I run the JUnit test again Hibernate will auto increment the last id value (instead of starting at 1 again). Can it have something to do with me never setting the hibernate.hbm2ddl.auto value in hibernate.cfg.xml ?

Code:
private long id;
      
   @Id
   @GeneratedValue
   public long getId() {
      return id;
   }
   
   public void setId(long id) {
      this.id = id;
   }


Code:
public void testInsertEntry() {
openSession();
beginTransaction();
       
Person person = new Person("Pancakes");
save(person);
       
endTransaction();
closeSession();
factory.close();
}


Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 6:01 pm 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:13 pm
Posts: 32
Location: Spain (GU)
Can you provide the *.hbm.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 6:03 pm 
Newbie

Joined: Mon Dec 18, 2006 4:14 pm
Posts: 3
Code:
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/stikkies</property>
<property name="connection.username">xxx</property>
<property name="connection.password">xxx</property>
       
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.pool_size">10</property>       
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

//Mapping classes omitted


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 6:23 pm 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:13 pm
Posts: 32
Location: Spain (GU)
I mean the Person.hbm.xml file. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 6:24 pm 
Newbie

Joined: Mon Dec 18, 2006 4:14 pm
Posts: 3
But I'm using annotations :-)

if I use <property name="show_sql">create-drop</property> the test will work fine, but if I change it back to "update" and then delete all rows hibernate will still start generating ID's starting from the last deleted row.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 5:09 am 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:13 pm
Posts: 32
Location: Spain (GU)
Maybe it can help you:
http://www.hibernate.org/hib_docs/refer ... on-id-hilo

It tells about Hi/Lo Algorithm

Regards


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