Hi all,


After further tests I think the problem is not relative to UUID nor primary 
keys but to properties from super classes that seem never persisted.



I've updated the Tutorial code to add a new class 
org.apache.cayenne.tutorial.persistent.Auditable with has some basic 
properties, then updated Artist class to override Auditable.

Gallery does not override it but uses the 2 new properties, so I can compare 
results. DBEntity is updated accordingly.



Test sources are available on github https://github.com/fredgi/Cayennetutorial/



Properties which are super class based are not persisted. Properties of the 
ObjEntity are.



One strange behavior : on first run, when tables are created, properties of the 
superclass are returned not null, but not saved in database. On the second run, 
when tables already exists the test fails : super properties are null & not 
saved.



I'm not familiar with Cayenne : I like concepts in use and try to evaluate 
Cayenne for a project, I don't know if i use it poorly to get such results.



Any help would be appreciated.



Regards,

Fred





De : Frederic Gilbart
Envoyé : dimanche 19 juin 2016 21:16
À : 'user@cayenne.apache.org' <user@cayenne.apache.org>
Objet : UUID as primary key



Hi all,



I'm looking for some information to use java.util.UUID as a «Meaningful Primary 
Key » as stated in 
https://cayenne.apache.org/docs/3.0/primary-key-generation.html .



I've planned to use a Listener onPreUpdate to initialize the value.

Every tries shown an Integer used in my VARCHAR column, and my UUID key unused 
(but a sequence value instead)

Modeler PK generation is « default ».
I'm using it that way

@PostAdd(Audit.class)
public void postAdd(Audit object) {
   object.setUuid(UUID.randomUUID());
   object.setCreatedBy("ME");
   object.setCreationDate(new Date());
}

Most of objects extends this abstract super class Audit.


Listerner is added to context at startup and  triggered as expected.



I'm using 4M3.


Do you know how to deal with this ?

One more thing : for all abstract super classes, should I duplicate properties 
on the overiding objects because without doing it values seems not persisted  ?

Regards
Fred.

Reply via email to