Hi does it happen if you don't do it for the else case (new Fact())? But I guess it is linked to a relationship maybe
Romain Manni-Bucau Twitter: @rmannibucau Blog: http://rmannibucau.wordpress.com/ LinkedIn: http://fr.linkedin.com/in/rmannibucau Github: https://github.com/rmannibucau 2014-05-14 19:53 GMT+02:00 Karl Kildén <[email protected]>: > Hi, > > I use openjpa with DTO and when I try to manage @Version I get an > exception: Detected attempt to modify field > "com.kildeen.ref.domain.BaseEntity.version" with value strategy "restrict". > > What I do is, I use find if the DTO has id. I then copy back the version > field but it seems It does not work since I get that exception... Can it be > done somehow? > > Code below: > > @Override > protected Fact toEntity(final FactDTO dto) { > Fact fact; > if (dto.getId() != 0) { > fact = em.find(Fact.class, dto.getId()); > } else { > fact = new Fact(); > } > > if (dto.getVersion() != entity.getVersion()) { > entity.setVersion(dto.getVersion()); > > } > > cheers
