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