Rob Spoor wrote:I take it that the model classes are mapped from JSON directly to your entities, right? If so, you're running into a bidirectional relation that is only set on one side. The unmarshalling from JSON creates new LoggingModel instances, and puts them into a list. It then sets that list on the created EmployeeModel instance. The EmployeeModel instance now has a reference to all of its LoggingModel instances. What is still missing is the reference in the LoggingModel instances to the EmployeeModel instance. The JSON unmarshalling doesn't set this because it simply doesn't know it should.
A quick solution is to fix these references yourself. A quick for-each statement will suffice:
There are some ways to fix this. One is to create POJOs for your REST responses. You end up mostly duplicating your class, but you can easily leave out the things you don't want.
I prefer the first way, because
it allows me to create different POJOs for retrieving EmployeeModel instances with nested Role instances, or the other way around. If you ignore these in your entities, you can only have one of these options
it will ignore anything I don't want. That includes any properties added by the JPA framework (I remember TopLink adding its own properties)
I see code where they have more or less choosen for this solution.
Another way to fix this is to mark the employeeRoleModel as ignored during serialization. How to do this depends on the serialization framework. For instance, for Jackson you'd use @JsonIgnore.
I do not understand the question sorry, I think due a lack of knowledge of my.
If you're not using an Entitymanager, then who's doing the persisting? Is this an EJB3 container?
Anyway, good luck on the Many-to-Many. I find that one to be the most challenging of all!
As I said before, ORM is not the same thing as SQL. Entity Objects don't link to other Entity Objects by key value. They link as Object properties (references).
Rob Spoor wrote:Are you sure that an Employee's unit cannot be changed? Perhaps that's where the issue lies, especially if you assign a different unit.