-2

I have a Pojo:

class Pojo{
   String name;
   String surname;
}

and a jpa/hibernate entity:

class Entity{
     Long id;
     String code;
     List<EntityPojo> ep;
}

finally the entity pojo

class EntityPojo{
    Long id;
    String name;
    String surname;
}

In my code I do:

//I receive a pojo from the rest call and I want to update
Entity entity = repo.findByCode("aCode");

//at this point my entity pojo IDs are correctly filled!

dozerMapper.map(pojo, entity);

//after the map the IDs are null!!
repo.save(entity); //BAM!

As you can see the mapping just deletes the IDs and this brings me to the constraint exception in hibernate...why is that?

Phate
  • 6,066
  • 15
  • 73
  • 138

1 Answers1

0

You didn't provide a code that isolates and reproduce the problem. From what you provided, at least things to check:

1) What id is in pojo instance? If it's null - here your result. Could be useful: Exclude Mapping Null Values

2) Check access levels. I'm not sure how Dozer currently working if fields are not public and have no public access methods.

3) Did you verify that fields are in the entity are null, not in a database? If you do - why this question has spring-data-jpa tag and code related to persistency level? If you don't - why are you sure that something wrong with Dozer, not with your database mapping?

In general - you don't seem to work on the question by yourself at all, because if you do - you would at least make an example with cleaned up database persistence layer after checking that it's not a place where you lose your fields. It's really hard to answer a question with mix of technologies and problem could be anywhere.

Dmitry Spikhalskiy
  • 5,379
  • 1
  • 26
  • 40