I've made a repository class (a class that handles all jpa methods) for each entity type with it's own entitymanagerfactory.
Now I've encountered the following error on my many to many relationship:
[junit][EclipseLink-7251] Exception Description: The attribute [ID] of class [Person] is mapped to a primary key column in the database. Updates are not allowed.
I have come to the conclusion that the different EMFs did in fact cause seperate persistence contexts, which caused problems like the validationException.
(I think this happened when 2 different instances of the same entity were managed in 2 different contexts and one of the instances changed it's state though i'm not certain)
Tested like this:
(relevant part of a junit test method)
OrderBill cheapOrder = new OrderBill(5, LocalDate.now()); weekRep.addWeek(cheapOrder.getOrderWeek()); //because of the cascade, both the cheapOrder and the week or now persisted in the DB and managed by weekRep OrderBill dbOrder = orderRep.updateOrder(cheapOrder); boolean t2 = weekRep.isManaged(cheapOrder); //true boolean t3 = orderRep.isManaged(cheapOrder); //false //It's because this returns false I assume both persistence contexts are different boolean t4 = orderRep.isManaged(dbOrder); //true //If i now use "cheapOrder" to change the order i get the error //If i now use "dbOrder" to change the order, db gets updated as expected