-->
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.  [ 4 posts ] 
Author Message
 Post subject: @Id annotation with java.util.UUID as Entity primary key
PostPosted: Mon Mar 20, 2006 3:09 pm 
Newbie

Joined: Thu Feb 23, 2006 6:44 pm
Posts: 4
I have an entity that has a java.util.UUID class as its primary key. The key is stored in the DB as an auto-generated uniqueidentfier.

How do I annotate this? Is this even possible to do?

/**
* Example entity
*/
import java.util.UUID
import javax.persistence.*;

/**
* Address class.
*/
@Entity
@Table(name = "T_ADDRESSES")
public class Address implements java.io.Serializable {

private UUID _uuid = null;
private String _streetAddress1 = null;

/**
* Common Constructor.
*/
public Address() {}

public void setUUID(UUID uuid) {
_uuid = uuid;
}

@Id // ??
@GeneratedValue //??
@Column(name = "ADDRESS_ID")

public UUID getUUID() {
return _uuid;
}

public void setStreetAddress1(String streetAddress1) {
_streetAddress1 = streetAddress1;
}

@Column(name="STREET_ADDRESS_1")
public String getStreetAddress1() {
return _streetAddress1;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 6:08 am 
Beginner
Beginner

Joined: Mon Dec 05, 2005 4:15 am
Posts: 36
there is a Hibernate uuid generator. You can use this generator using the annotation @GenericGenerator(name="...", strategy = "uuid"). See the Hibernate Annotations reference, section 2.4.2.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 8:03 pm 
Newbie

Joined: Thu Feb 23, 2006 6:44 pm
Posts: 4
I have annotated my id with the following but still receive errors

@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name="ADDRESS_ID")
public UUID getId() {
return _id;
}

From the following de-bugging output am I to expect that the SerializableType cannot process the column ADDRESS_ID (which is of type uniqueidentifier)? Or is it that a java.util.UUID cannot be constructed?

DEBUG: Mar 23, 2006 15:54:01 SessionImpl: SQL query: SELECT * FROM T_ADDRESSES
DEBUG: Mar 23, 2006 15:54:01 AbstractBatcher: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG: Mar 23, 2006 15:54:01 ConnectionManager: opening JDBC connection
DEBUG: Mar 23, 2006 15:54:01 AbstractBatcher: preparing statement
DEBUG: Mar 23, 2006 15:54:01 AbstractBatcher: about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG: Mar 23, 2006 15:54:01 Loader: processing result set
DEBUG: Mar 23, 2006 15:54:01 Loader: result set row: 0
DEBUG: Mar 23, 2006 15:54:01 SerializationHelper: Starting deserialization of object
INFO : Mar 23, 2006 15:54:01 SerializableType: could not read column value from result set: ADDRESS_ID
DEBUG: Mar 23, 2006 15:54:01 AbstractBatcher: about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG: Mar 23, 2006 15:54:01 AbstractBatcher: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG: Mar 23, 2006 15:54:01 AbstractBatcher: closing statement


I could probably use a more concrete example than what is in the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
either map it as a String
or write a user type paiing UUID to your underlying DB type and use @Type

_________________
Emmanuel


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