Reputation: 19589
If multiple entity/persist class instance OWN the some record of one table.
then what happend(suppose in a multithreaded application)? Is it legal in Hibernate?
Upvotes: 0
Views: 77
Reputation: 5700
Yes It is legal to have more than one entity for single table. This is the problem called Granularity.
Hope This is helpful!
Upvotes: 2
Reputation: 8068
What do you mean by own? A composition of P
owning C
using UML
semantics? If so, you should have an unique constraint defined on the table, P
is mapped to. In addition, you should map the property of P
holding C
, with cascade=”delete”. With all this in place, one thread should succeed in persisting C
, owned by many threads in terms of having different P
s owning the same C
. All the others should fail to commit, because of the unique constraint defined.
Upvotes: 1