Data lost with AttributeConverter


I do want to store a more complex object structure serialized as JSON to a single text field to the database. I tried to use an AttributeConverter as following:

  • A simple data container class.

  • A converter to serialize a List<NameElement> to JSON and back.

  • My Entity class, containing a List<NameElement>.

  • an EJB with all entity manager code needed for the Country entity.

  • An arquilian unit test for the code above.

The unit test class contains 3 different tests, doing mostly the same:

  • Create an Country object

  • Add 3 names to the list: A, B and C

  • Persist this object to DB

  • Reload from DB, check if the name list is as expected (A, B, C)

  • Reorder the name list to A, C, B

  • Write back to DB

  • Reload from DB and check again if the name list is as expected (A, C, B).

The funny thing is: Two tests work but one test fail, because the DB still contains the order A, B, C.
The difference between the tests is:

  • resortDetached() makes the EntityManger#merge() with an changed but detached object. This works.

  • resortInTransaction() calls a method within the EJB to load and modify the list in one transaction. This time, the modification is not written back to DB and the test fails!

  • resortInTransaction_ButChangeName() same as resortInTransaction(), but this time, not only the name list, but also a 'simple' attribute of the entitiy object is changes. Because of this change, Hibernate detects a change, wants to save the result and 'by accident' also updates the name list. So this test works.

So as a conclusion, I found out, that in the test case resortInTransaction() Hibernate is blind for the changed data! It does not even request the converter to serialize the data. The changes just got lost.
If you change the Country - entity to @DynamicUpdate(true), also the third test fails, because now he only update the changed county name.
I also had similar problems with JSE environment, but did not spent too much time here. I hope, one concrete example of the problem is enough.

Sorry If I report something wrong or unexpected, but this is my first issue, reported here.


Wildfly 8.2.1 on Windows 7. DB may be Postgres, HSQL or H2


Chris Cranford
January 17, 2016, 4:35 AM

I ported your unit tests into a hibernate-orm based unit test class and in none of the 3 supplied scenarios could I reproduce the problem against the master branch. I'll be more than willing to provide the unit tests as a PR if needed.

Martin Metz
January 18, 2016, 9:34 AM

What is "PR"? Can I help in any case?
Nevertheless, I got my initial problem working, using a UserType implementation instead of the AttributeConverter. So I'm personally not urgently waiting for a solution.

Steve Ebersole
February 27, 2016, 11:49 PM

AttributeConverters underwent additional support work in both 5.0 and 5.1. attempted to reproduce the reported problem and was unable to do so. So at this point I have to reject this, until/unless someone can help us show it failing as reported.




Martin Metz

Fix versions






Suitable for new contributors


Requires Release Note


Pull Request





Affects versions