Hello,
I am currently using hibernate 3.6.0.Final as JPA implementation.
I have an entity where I would like to use a primary key with "java.lang.Byte" as datatype.
Code:
@Entity
public class EntityByte implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Byte id;
...
Schema generation works and everything looks o.k. within the underlying mysql database.
Code:
CREATE TABLE `entitybyte` (
`id` TINYINT(4) NOT NULL AUTO_INCREMENT,
`text` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
But when a new object is to be persisted an exception is thrown:
Code:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: unrecognized id type : byte -> java.lang.Byte
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)
at example.bytepk.App.run(App.java:57)
at example.bytepk.App.main(App.java:24)
Caused by: org.hibernate.id.IdentifierGenerationException: unrecognized id type : byte -> java.lang.Byte
at org.hibernate.id.IdentifierGeneratorHelper.get(IdentifierGeneratorHelper.java:132)
at org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:86)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:98)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2327)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2834)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672)
... 2 more
In the "org.hibernate.id.IdentifierGeneratorHelper.get"-source there are only case distinctions for
- Long
- Integer
- Short
- String
- BigInteger
- BigDecimal
- and CustomType(which is something hibernate specific, I think).
As I want the project to be rather independent from the JPA "implementation".
Is there a JPA-conform workaround for this?
Or is this considered a bug within Hibernate?