1

There seems to be quite a few questions on this, but none resolve my issue.

I'm trying to use hibernate annotations to generate a UUID.

My annotations are below...

@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
public UUID getUuid() {
    return uuid;
}

I'm using MySQL 5.2 with Hibernate 3.5.6 in my pom.xml as shown below...

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>

Upon starting my application, I get the following error...

ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table players (uuid tinyblob not null unique, espnid integer, espnUrl varchar(255), firstname varchar(255), lastname varchar(255), primary key (uuid))
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - BLOB/TEXT column 'uuid' used in key specification without a key length

What's the correct annotation? Am I using an incorrect hibernate version? Am I using something incorrectly with MySQL?

My dialect details are below...

<beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
                </beans:prop>
                <beans:prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory
                </beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
                <beans:prop key="hibernate.hbm2ddl.auto">create</beans:prop>
            </beans:props>
        </beans:property>

The error implies the length isn't specified, but if I enter this into @Column nothing changes.

I'm only using an older version of hibernate due to the hibernate-annotations only going up till then, if this is now a dead repo I'll move to a later version.

David
  • 19,577
  • 28
  • 108
  • 128

1 Answers1

3

I think the problem is the type returned by the getUuid() method. It needs to be a String according to hibernate docs.

uuid:

uses a 128-bit UUID algorithm to generate identifiers of type string that are unique within a network (the IP address is used). The UUID is encoded as a string of 32 hexadecimal digits in length.

Community
  • 1
  • 1
dcernahoschi
  • 14,968
  • 5
  • 37
  • 59
  • Ah, I thought that too, but from Hibernate 3.6 I thought they'd supported the UUID data type? Just reading from http://stackoverflow.com/questions/4346898/problems-mapping-uuid-in-jpa-hibernate – David Mar 31 '13 at 17:06
  • You specified hibernate version 3.5 in your question. Yes, the linked question applies very well for hiberante 3.6 – dcernahoschi Mar 31 '13 at 17:22
  • Ah, sorry I will edit my question, if I need to update hibernate I'd be more than happy to, but from looking at the maven repository the annotations repository only lasted till 3.5.6, is that a dead repo now? – David Mar 31 '13 at 17:36
  • Sweet, looks like the hibernate-annotations is in fact no longer required and I can just use hibernate-core, thanks very much, will update to hibernate4. – David Apr 08 '13 at 09:09