Hello,
I'm trying to create a Read-Only entity relationship. Assuming that
Entity E1 has a OneToMany relationship with E2, I would like **not** to
be able to edit E2 from E1 (so E1.getE2().setSomeAttribute(-) should not
be reflected in the database). By default, when I fetch E1 from the
EntityManager it becomes managed, as well as E2, so every changes made
are passed to the database.
For simple types I can just do "@Column(updatable=false)", but for
entities it doesn't seem to work. Does "@JoinColumn(updatable=false)"
for entities means that the **FK cannot change**, but the **state of
entity can**?
If so, then in "Pro JPA 2 - Mastering the JAva Persistence API" book
from Apress, Chapter 10 - Advanced Object-Relational Mapping, "Advanced
Mapping Elements" there is the following text:
"No new entities will be persisted, and existing entities will never be
updated.".
It firmly refers to the "entities" but should I understand it as
"entity state" rather than "entity" itself?
Nevertheless, the book also mentions:
"JPA does not really define any kind of read-only entity, although **it
will likely show up in a future release.**"
Does the JPA 2.1 Expert Group have some @ReadOnly spec-compliant
feature in plans?
Thanks in advance for your answer.
Regards,
Piotr
--
http://piotrnowicki.com