Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Postgresql and UUID eclipselink 2.4.0

The @UuidGenerator  is for generating a UUID in Java and storing it to the
database as a String (varchar) or byte[] (varbinary).

To use the custom Postgres UUID type you will need to write your own
Converter (@Convert, @Converter) to handle the conversion of whatever type
Postgres returns from JDBC to/from the Java type you want to use.

See,
http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_converter.htm#CHDEHJEB


Edward Mann-3 wrote:
> 
> I have been trying to figure out how to get the native uuid type in
>         postgresql and eclipselink to work together. I have a simple
> table for
>         testing:
>         
>         CREATE TABLE elink
>         (
>           el_id uuid NOT NULL DEFAULT uuid_generate_v4(), -- elink id
>           el_name character varying(255), -- elink name
>           CONSTRAINT el_pkey PRIMARY KEY (el_id )
>           DEFERRABLE INITIALLY IMMEDIATE
>         )
>         WITH (
>           OIDS=FALSE
>         );
>         ALTER TABLE elink
>         OWNER TO emann;
>         COMMENT ON COLUMN elink.el_id IS 'elink id';
>         COMMENT ON COLUMN elink.el_name IS 'elink name';
>         
>         
>         And the annotation on the field for id is:
>         
>         @Id
>                 @Column(name="el_id")
>                 @UuidGenerator(name="uuid")
>                 @GeneratedValue(generator="uuid")
>                 private UUID elId;
>         
>         I have also tried the custom UUIDSequence mentioned on the
> website,
>         however that did not work either. I get the following error
> (this is the
>         UUIDSequence native to 2.4.0):
>         
>         Exception [EclipseLink-3002] (Eclipse Persistence Services -
>         2.4.0.v20120608-r11652):
>         org.eclipse.persistence.exceptions.ConversionException
>         Exception Description: The object
>         [66FB2FFB-2735-4A8C-AFDE-19246C78CC16], of class [class
>         java.lang.String], from mapping
> 
> [org.eclipse.persistence.mappings.DirectToFieldMapping[elId-->ELINK.el_id]]
> with descriptor [RelationalDescriptor(model.Elink -->
> [DatabaseTable(ELINK)])], could not be converted to [class [B].
>         
>         
>         So i am really curious about what is the proper way to get this
> to work
>         using uuid type in postgresql. 
>         Any help is welcome, thanks in advance.
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.eclipse.org/forums/index.php?t=thread&frm_id=111&S=1b00bfd151289b297688823a00683aca
EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/Postgresql-and-UUID-eclipselink-2.4.0-tp34262300p34266503.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top