christophknabe / spring-ddd-bank

A sample project following Domain Driven Design with Spring Data JPA
GNU Lesser General Public License v2.1
512 stars 125 forks source link

Make AccountAccess an Associative Class without own Identity #12

Open christophknabe opened 6 years ago

christophknabe commented 6 years ago

AccountAccess is intended as an associative class, that is a materialization of an association between Client and Account. The meaning is: The Client has the right to manage the Account. The associative class is necessary, as the association "Client can manage Account" has an attribute which states, if the Client is the owner of the Account, or only a manager. It was quickly implemented as a subclass of EntityBase<AccountAccess>. As an undesired consequence the associative class has an own ID. This implies, that the persistence would tolerate several links between a Client and an Account, even with contradictory values of the attribute isOwner. This is certainly not desirable. A better solution would be to make the associative class have a primary key composed of the Client and the Account linked together. How to accomplish this with JPA has to be found out.