JPA2 / Hibernate - @Version annotation

12 views
Skip to first unread message

ggran...@gmail.com

unread,
Sep 16, 2015, 12:43:59 PM9/16/15
to minuteproject
Florian,

Is there support in the code generation for inserting an @Version annotation on certain columns?
Regards,
-Greg

Florian Adler

unread,
Sep 17, 2015, 2:42:34 PM9/17/15
to minute...@googlegroups.com
Hello Greg,

You can add a new convention (version-convention) inside convention node.
It has a attribute pattern that contains the list of columns (it should be case insensitive).

In your case you should have something like 

<conventions>

...

<version-convention pattern="lockVersion"/>

</conventions>


Best regards,


Florian


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "minuteproject".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse minuteprojec...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

ggran...@gmail.com

unread,
Sep 21, 2015, 1:05:00 PM9/21/15
to minuteproject
Florian,

Thanks for the reply.  That worked.

I have a few more related questions, however, I would like to research and answer these questions for myself rather then post each question and waiting for an answer.  Are these "<convention>" options documented somewhere?  Perhaps I can discover them myself in the source code?

If not here are a few questions I currently have:

1) how do I get the code generation to specify CascadeType.ALL ?
2) can I affect the code generation to plurals for collection names?
3) entities that are children of a collection have a member that is essentially a parent reference.  Can I affect the name that is generated in this case?

Regards,
-Greg

Florian Adler

unread,
Sep 21, 2015, 4:58:01 PM9/21/15
to minute...@googlegroups.com
Hi Greg,

You can find some documentation at https://minuteproject.wikispaces.com/Configuration 

Regarding point 1) I do not have (yet) option for cascadeType.

Regarding points 2 and 3 there are some conventions to change the name of the variables to have plurals for associated collection oneToMany/manyToMany, to strip Pk or Id ending DB names etc.
The idea is get java variable looks like java name and not raw db translated name.
By default the name are generated to ensure uniqueness of variables (for compilation purpose).

You can alter this behavior by providing convention that refine the name of the column/table.

The convention

<reference-naming-convention type="apply-referenced-alias-when-no-ambiguity" is-to-plurialize="true" />

Should provide you what you need for point 2) for oneToMany relationship

whereas

<reference-naming-convention type="apply-many-to-many-aliasing" is-to-plurialize="true" />

should tackle point 2) for m2m relationship


Regarding point 3)
If I understand correctly, you would like to modify the name of the variable that correspond to the foreign key.
In this case there are 2 ways:
Explicitly : 

<entity name="yourentity">

<field name="yourfield" alias ="your preferred name"/>

</entity>

The entity node is at the same level as conventions (ie under enrichment)

By convention:

<column-naming-convention type="apply-strip-column-name-suffix" pattern-to-strip="ID" />

To remove endding ID, etc

I hope it helps,

Best regards,

Florian.

Reply all
Reply to author
Forward
0 new messages