openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikolas Everett" <nik9...@gmail.com>
Subject Fwd: UUIDs
Date Wed, 30 Apr 2008 14:49:07 GMT
I tried the attached message on the users list but didn't get any response.
Will someone on the dev listserve help?  I'm researching an ORM solution for
our company, and can't in good conscience pick one with quiet listservs.
Thanks,

--Nik

---------- Forwarded message ----------
From: Nikolas Everett <nik9000@gmail.com>
Date: Mon, Apr 28, 2008 at 5:20 PM
Subject: UUIDs
To: users@openjpa.apache.org


I tried to search the archives and didn't find anything on this.  I'm using
openjpa 1.0.2 and having problems with UUIDs backed into postgres 8.2.

I have a class like:
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames="uuid")})
public class Account {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @Persistent
    @Column(nullable=false)
    @Externalizer("java.util.UUID.toString")
    @Factory("java.util.UUID.fromString")
    @ElementType(UUID.class)
    private UUID uuid;

...getters and setters...
}

The uuid column is created as a character varying 255, which is fine for
now.

I  have a method like this:
    protected Account getAccountByUuid(UUID uuid) {
        Query findAccount = this.em.createQuery("SELECT a FROM Account a
WHERE a.uuid = ?1");
        findAccount.setParameter(1, uuid);
        try {
            return (Account) findAccount.getSingleResult();
        } catch (NoResultException e) {
            Account account = new Account();
            account.setUuid(uuid);
            this.em.persist(account);
            return account;
        }
    }

Which throws an exception like this:
Exception in thread "main" <openjpa-1.0.2-r420667:627158 nonfatal user
error> org.apache.openjpa.persistence.ArgumentException: The parameter "0"
is of type "java.util.UUID", but the declaration in the query is for type
"java.lang.String".
    at
org.apache.openjpa.persistence.QueryImpl.validateParameter(QueryImpl.java:270)
    at
org.apache.openjpa.persistence.QueryImpl.validateParameters(QueryImpl.java:250)
    at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:231)
    at
org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:300)
    at com.companyname.Classname.getAccountByUuid(FetchData.java:73)

This isn't the behavior documented here:
http://openjpa.apache.org/docs/latest/manual/ref_guide_pc_scos.html#d0e21916

What can I do?

Thanks in advance,

--Nik

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message