cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: UUID as primary key >> class hierarchy persistence MappedSuperclass
Date Sat, 25 Jun 2016 21:49:19 GMT
Hi Frederic,

> For my overview on Cayenne do you mean Cayenne cannot persists class hierarchy' properties
? How may I manage JPA @javax.persistence.MappedSuperclass in Cayenne ?

It can, just differently. There's no MappedSuperclass idea.

> Auditable is just an exemple to reproduce my case from a more complex project which has
a lot of superclasses and doing interfaces for each is not an option (poor OOP design).

You can use abstract superclass instead of an interface, with abstract getters/setters. Concrete
subclass mapped as a Cayenne entity will generate all the persistent methods for you, effectively
implementing your interface based on the model. The only thing you lose compared to MappedSuperclass
is the ability to reuse object-to-db mapping from the superclass, but you won't lose anything
in terms of OOP.

> Moreover the use of listeners on super abstract classes could be a great advantage but
seems not useful if they can't be persisted.

You can still define listeners working off the common abstract superclass.

> Is an evolution doable in a reasonable time ?

We are actually thinking of redoing parts of inheritance mapping in Cayenne, so a concept
of MappedSuperclass may come to play (to reuse the mapping). It won't happen quickly though.
Still I hope the abstract superclass approach will get you going right away.

Andrus


> On Jun 22, 2016, at 2:42 PM, Frederic Gilbart <fgilbart@capsiel.fr> wrote:
> 
> Hi,
> 
> 
> 
> Thank you Andrus for your answer.
> 
> 
> 
> For my overview on Cayenne do you mean Cayenne cannot persists class hierarchy' properties
? How may I manage JPA @javax.persistence.MappedSuperclass in Cayenne ?
> 
> 
> 
> Auditable is just an exemple to reproduce my case from a more complex project which has
a lot of superclasses and doing interfaces for each is not an option (poor OOP design). Moreover
the use of listeners on super abstract classes could be a great advantage but seems not useful
if they can't be persisted.
> 
> 
> 
> Is an evolution doable in a reasonable time ?
> 
> 
> 
> Best Regards,
> 
> Fred
> 
> 
> 
> 
> 
> -----Original Message-----
> 
> 
> 
> Hi Frederic,
> 
> 
> 
> Looking at the GitHub example, my recommendation is to avoid mapping Auditable in Cayenne
> 
> as an entity. The easiest alternative is to make Auditable an interface and let appropriate
> 
> entities implement it.
> 
> 
> 
> Andrus
> 
> 
> 
> 
> 
> 
> 
> 
> 
> De : Frederic Gilbart
> Envoyé : lundi 20 juin 2016 21:25
> À : 'user@cayenne.apache.org' <user@cayenne.apache.org>
> Objet : RE: UUID as primary key
> 
> 
> 
> 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<mailto: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.
> 


Mime
View raw message