You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by ben short <ja...@gmail.com> on 2007/09/06 00:46:55 UTC

@SequenceGenerator question

Hi,

I have a simple class as shown below...

Entity
@SequenceGenerator(name="CategoryIdGen", sequenceName = "CategoryIdSeq")
public class Category
    {
    @Id
    @Column(name="id")
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator =
"CategoryIdGen")
    private Long mId;
    }

Given the following code and assuming that the sequence is equal to 0,
I would expect that category would get an id of 1 and category2 an id
of 2. But this is not the case, category gets an id of 1 and category
gets an id of 51.

        EntityManager em = entityManagerFactory.createEntityManager();

        em.getTransaction().begin();

        Category category = new Category();
        category.setName("Category");
        category.setDescription("Category");
        Category category2 = new Category();
        category2.setName("Category");
        category2.setDescription("Category");

        em.persist(category);

        em.persist(category2);

        em.getTransaction().commit();

It would seem that the db allocates 50 ids at a time, as expected, yet
openjpa doesn't use them up, it just calls the generator again.

I'm using postgresql and openjpa-1.1.0-SNAPSHOT.

I have search the JIRA but cant see a bug of this description. Is this
a known issue?

Regards

Ben Short