2

Here's what I had to write to get UUID working as a primary key, with full UUID types (on all ends) in hibernate. Since this relies on some Hibernate specific code, what would I have to do to convert this code to work on eclipselink?

package com.lm.model;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.UUID;

@Entity
@Table(name = "tasks")
public class Task {

@Id
@NotNull
@Type(type = "pg-uuid")
@GeneratedValue(generator = "myUUIDGenerator")
@GenericGenerator(name = "myUUIDGenerator", strategy = "uuid2")
@Column(name = "task_id", columnDefinition = "uuid")
private UUID id;

@NotNull
@Size(min = 1, max = 100)
private String description;

public String getDescription() {
    return description;
}

public void setDescription(final String description) {
    this.description = description;
}

public UUID getId() {
    return id;
}

public void setId(final UUID id) {
    this.id = id;
}
}
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
  • I'm pretty sure I know, but just in case ... what was "not working" about it that required this? And where does the type definition `pg-uuid` come from? Is it built in to Hibernate? – Craig Ringer Sep 20 '14 at 22:56
  • @CraigRinger I don't know that I *really* understand the `pg-uuid` thing, but it appears to be required, otherwise I got a `expected uuid but got bytea` or some such error. this answer might help point to the explanation. http://stackoverflow.com/a/7479035/206466 . It was *really* painful trying to figure out how to get UUIDs working with postgres and hibernate, because there are many *partial* pieces of the solution that I found. This question is sort of a preempt because I'm finding less information with eclipselink (which could mean it actually just works, or that one one tries). – xenoterracide Sep 20 '14 at 23:03
  • I'm also not sure what the replacement generator in eclipselink would look like, as I didn't find that. – xenoterracide Sep 20 '14 at 23:04

0 Answers0