How to handle unique constraint in Entity (AggregateRoot) in Lagom? - event-sourcing

In our case we are creating a Ticket entity and in that Email Id has to be unique, how to achieve this using the Lagom Framework?

Related

Spring Boot JPA - Entities

Hopefully, you can help me with the following doubts that I have.
So I have an entity called User that has some columns like Nationality, Gender, Professional Status. And I have an entity for each column referred.
I'm looking for the best way to define this.
Should I apply a ManyToMany relationship between those tables? Since Users can have the same Nationality and Gender?
When I try to implement this, Spring is creating a third table automatically and I don't understand the need.
Having the following shouldn't be enough?:
Table User:
id,
name,
id_nationality.
id_gender,
id_professional_status
Table Nationality:
id,
nationality
(etc)
Why Spring is creating another table called user_nationality?
Thanks in advance.
Whenever we are using the ManyToMany relationship in that case a separate table will be created containing both primary keys of the tables involved in the new relationship.

Can multiple Accounts/Contacts share Customer Address in Microsoft Dynamics 365

My understanding is that there is a ParentId in CutomerAddress which will be either the AccountId or ContactId. Also, the Account entity has an AddressId.
How does the relationship flow between Account and CustomerAddress? Is the Account referencing CustomerAddress?
If I create a new Account/Contact that has the same CustomerAddress of a previously existing Account, will the same AddressId be used or a different record will be created in CustomerAddress for this Account/Contact? Usually, at least the Telephone number column will be different which will result in creating a new record but if all fields are similar will a new CustomerAddress record still be created?
No, CustomerAddress records cannot be shared. The relationship between Account : CustomerAddress and Contact : CustomerAddress is 1:N. There is no N:M intersection.
It makes it simple to understand, but the downside is we may end up with quite some duplicated data.

Association mapping in microservice

I have two Microservices. Let's say student & library.
student & library - eureka clients
The microservices have a common DB
The scenario is - A student can issue (or take) multiple books from the library.
In Monolithic Application:- This will be implemented by anotating#OneTOMany on List of LibraryBook in StudentEntity and adding one table where we will store each book id for student.
Currently what i have tried
I have loose mapping (or binding ) of data between the data. I have created a table in DB with two columns studentId and bookId and when a student takes a book from library I add the bookId in the table and delete the record when book is returned.
For saving -
StudentBook studentBook = new StudentBook();
studentBook.setStudentId(123);
studentBook.setBookId(456);
studentBookRepository.save(studentBook); // studentBookRepository extends JPA Repository
For Deleting-
studentBookRepository.deleteByBookIdAndStudentId(456,123);
The problem in this implementation is that I always have to verify the bookId before saving the records.
Is there any better way to implement this?
How to implement #OneToMany relationship in Microservices?
(Or can we even implement Association mapping in microservices)
(Or can we even implement Association mapping in microservices)

What's a good way to handle Generic Foreign Keys in JPA?

We have an Spring 3.2, Hibernate 4.2 application.
Our application has an upload module, where you can basically upload all kinds of files. A file upload generates also a database entry:
id, directory, filename, mimeType, userId
So basically it should be possible to upload a file from everywhere in the application. And we don't want a new UploadEntity for every possible Entity. So we thought about using some kind of generic table for uploads:
id, directory, filename, mimeType, userId, FOREIGN_KEY
The problem of course is, that we can't set a concrete data type for this foreign key in JPA, because it can point to Entity A or B or C or ... We use UUID as keys in our application, so we thought about two solutions:
Make the foreignKey simply of type UUID and always save the foreign entity's id.
Make the foreignKey of type Object with a #ManyToOne annotation, but of course we can't provide a target entity for that.
But maybe there's some other much better/easier solution for this. What do you think?
I forgot to tell you, that each entity we use implements Persistable<UUID>, so is it possible to use this interface as type for the foreign key?
Btw: We need never to use the reference from UploadedItem -> SomeEntity. We only need the other way: SomeEntity -> UploadedItem.

Doctrine Foreign Key Issues Symfony

I'm getting a list of 'team' entities where each 'team' entity has two foreign keys to a 'user' entity. When a 'team' entity is created from a query, the entity will also end up containing all data for the two user accounts. I don't want this to happen because it contains sensitive data like the password. This is OK to have in certain features of this application, but currently I am creating a RESTful API (FOSRestBundle) and returning a team entity through the api gives someone access to sensitive data.
Currently, this is how I get all team entities:
public function findAllTeams()
{
return $this->getEntityManager()
->createQuery("SELECT t FROM MyBundle:TableTeam t")
->getResult();
}
The team table has two foriegn keys: pidOne and pidTwo that map to the user account table.
Is there a way I can modify this function such that it does not automatically link the user account data with team entity?
THANKS
Use
->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true)

Resources