-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with using java byte array as primary key
PostPosted: Thu Jul 17, 2008 7:50 am 
Newbie

Joined: Thu Jul 17, 2008 7:35 am
Posts: 2
Hello,

So i want to use for my program hibernate annotations and my class should have a byte array as primary key. The key itself is not generated but set by user. I have the problem, that hibernate is mapping the byte[] as a BLOB, but i cannot assign a length. My class looks like this:

Code:
@Entity
@Table(name="room")
public class Room
{
   private byte[] ID;   
   private String comIP;


   @Id
   public byte[] getID()
   {
      return ID;
   }
   public void setID(byte[] id)
   {
      ID = id;
   }

   @Column
   public String getComIP()
   {
      return comIP;
   }
   public void setComIP(String comIP)
   {
      this.comIP = comIP;
   }

}


When creating the table hibernate gives the following error:

13:43:48,640 ERROR SchemaExport:325 - Unsuccessful: create table room (id tinyblob not null, comip varchar(255), primary key (id))
13:43:48,640 ERROR SchemaExport:326 - BLOB/TEXT column 'id' used in key specification without a key length


Before i started to use hibernate annotations i fixed this problem by using the type varbinary(20), i specified this in the mapping file like this:

<id name="ID">
<column name="ID" sql-type="varbinary(20)"/>
<generator class="assigned"/>
</id>


But i really want to use annotations and i have tried to get it working for hours and hours but i couldnt find a solution. I tried to make hibernate use the varbinary type by using the @Type annotation, but it cannot find the type.

I would really appreciate if someone can help me here with this problem. I can use any solution, does not have to be by using the varbinary type.

Thanks alot!

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 8:21 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

You can specify the type of DB column like so:

Code:
@Column(name="id", columnDefinition="varbinary(20)")


NOTE: the name attribute is optional

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 6:23 pm 
Newbie

Joined: Thu Jul 17, 2008 7:35 am
Posts: 2
thank you very much andy, now its working. too bad i couldnt find that attribute earlier :(


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.