-->
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: JPA with byte primary key and GenerationType.IDENTITY
PostPosted: Wed Nov 17, 2010 6:46 am 
Newbie

Joined: Wed Nov 17, 2010 6:15 am
Posts: 1
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?


Top
 Profile  
 
 Post subject: Re: JPA with byte primary key and GenerationType.IDENTITY
PostPosted: Fri Jan 13, 2012 11:26 pm 
Newbie

Joined: Fri Jan 13, 2012 11:16 pm
Posts: 6
Yes..You are right.


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.