-->
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: Hibernate not using sequences correctly
PostPosted: Fri Sep 15, 2006 4:04 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hibernate version: version that comes with JBoss 4.0.4 GA

Mapping documents: none, annotations and EJB3 used

Name and version of the database you are using: PostgreSQL 8.1.4

I am currently experimenting with EJB3 in JBoss, and have encountered an issue with using sequences created by @SequenceGenerator and used with the @GeneratedValue.

Code:
@SequenceGenerator(name = "Institution_Sequence", initialValue = 1, sequenceName = "institution_seq")

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Institution_Sequence")


My entity setup is as follows Student, Course, Institution, and Location. The relationships between the entities are a
    Student -> Course = Many to Many with the Course entity 'owning' the relationship
    Course -> Institution = Many to Many with the Institution entity 'owning' the relationship
    Institution->Location = Many to One with the with Institution 'owning' the relationship (not sure about Many to One but the Institution entity has the JoinColumn annotation)
I have a very simple driver program just to test one relationship as below:

Code:
public void populateDatabase() {
        Location not = new Location();
        not.setLocation("Nottingham");
        mEntityManager.persist(not);
       
        Location lon = new Location();
        lon.setLocation("London");
        mEntityManager.persist(lon);
       
        Location she = new Location();
        she.setLocation("Sheffield");
        mEntityManager.persist(she);
       
        Institution uni = new Institution(not);
        uni.setName("Nottingham Trent University");
        mEntityManager.persist(uni);
       
        Institution uni2 = new Institution();
        uni2.setName("Nottingham University");
        uni2.setLocation(not);
        mEntityManager.persist(uni2);
    }


The program works fine, but any records inserted have the PK starting from 50, and the id of each entity is an int datatype.

Does anyone have any idea why it is starting from 50 ? I have also checked in the DB itself and the Sequence should start from 1, plus it does not seem to get incremented correctly (increment by 1 for 3 inserts ??).

Can anyone help ?

Thanks in advance,

Andy[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 9:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
allocationSize=1

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 3:15 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Emmanuel,

adding the "allocationSize=1" attribute to the @SequenceGenerator has fixed the problem.

Thanks,

Andy


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.