-->
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: ID Generator bug in JPA implementation ??
PostPosted: Tue Feb 13, 2007 3:59 am 
Newbie

Joined: Mon Dec 11, 2006 10:28 am
Posts: 7
I do not like to crosspost, but I posted this probably in the wrong forum (Hibernate users) and therefore never got an answer. Since this is a JPA related problem I try again here:

I use the latest version of hibernate (3.2.1 GA) and the same version of Annotations and EntityManager and have the following problem:

I have an entity which has the following SQL definition:

Code:
/*==============================================================*/
/* Table: CmdQueueIn                                            */
/*==============================================================*/
create table MTRACKER.CmdQueueIn
(
    CmdQueueInId         bigint                         not null global autoincrement,
    Type                 int,
    Cmd                  varchar(2048),
    CmdState             int,
    MLUser               bigint                         not null,
    ExecutionTime        timestamp,
    FinishTime           timestamp,
    ExecutionServer      varchar(64),
    ScheduleString       varchar(64),
    RetryCount           int,
    ResultMessage        varchar(256),
    RecordState          int                            not null default 1,
    CDate                timestamp                      not null default current timestamp,
    MDate                timestamp                      not null default current timestamp,
    constraint PK_CMDQUEUEIN primary key (CmdQueueInId)
);


The global autoincrement for the PK field CmdQueueInId means, that the database server automatically generates a primary key value for every insert.

I created a Java class with the following annotation for the primary key field cmdQueueInId:

Code:
    .......
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "CmdQueueInId", nullable = false)
    private BigInteger cmdQueueInId;
    .....


When inserting a new record I get the following exception:

Quote:
javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:176)
at $Proxy16.persist(Unknown Source)
at com.trixpert.dao.CmdQueueInDAO.save(CmdQueueInDAO.java:46)
at com.trixpert.test.dao.CmdQueueInDAOTest.testCreateNewCmd(CmdQueueInDAOTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at
......
Caused by: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFactory.java:59)
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:35)
at org.hibernate.id.IdentityGenerator$BasicDelegate.getResult(IdentityGenerator.java:157)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2108)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2588)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
... 34 more


I use a SYBASE Adaptive Server Anywhere Database.

Background:
========

The code works fine with TopLink, so I guess this is a bug in the JPA implementation of Hibernate.

The problem is, that the SQL type BIGINT may be signed or unsigned. In case it is unsigned, a long in the Java language is NOT big enough! Therfore the mapping for primary keys of SQL BIGINT has changed to java.math.BigInteger.

It seems, that the ID generator of the hibernate implementation does not support this datatype, at least this is what I guess after reading the stack trace:

Quote:
Caused by: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFactory.java:59)


Is this a problem or am I missing something here? Many thanks for your help and feedback.

Tom


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 7:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually you can create you own IdentifierGenerator (copy IdentityGenerator) and adapt it to make it work for BigInteger

Open an Hibernate JIRA issue and see if people vote for such an identifier generator, but this is a very uncommon requirement.

Toplink goes beyond the spec in this case
Quote:
Theprimarykey(orfieldorpropertyofacompositeprimarykey)shouldbeoneofthefollowingtypes:
anyJavaprimitivetype; anyprimitivewrapper type; java.lang.String; java.util.Date;
java.sql.Date. Ingeneral, however, approximatenumerictypes(e.g., floatingpoint types)should
neverbeusedinprimarykeys.Entitieswhoseprimarykeysusetypesotherthanthesewillnotbeporta-
ble. Ifgeneratedprimarykeysareused, onlyintegral typeswill beportable. Ifjava.util.Dateis
used as a primary key field or property, the temporal type should be specified asDATE.

_________________
Emmanuel


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.