Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Attribute Converter not working properly on lists
Attribute Converter not working properly on lists [message #1783338] Mon, 12 March 2018 04:38 Go to next message
Eclipse UserFriend
Payara 4.1.2.181 (and correponding eclipselink version)

Hello everyone,

I want to store as a json string a list of instances representing notes (as a string, a user id and a date) so I am using an attribute converter to convert from a List<Note> to a String :
@Converter(autoApply = true)
public class NotesAttributeConverter implements AttributeConverter<List<Note>, String> {
    private Gson gson = new Gson();

    @Override
    public String convertToDatabaseColumn(List<Note> notes) {
        return gson.toJson(notes);
    }

    @Override
    public List<Note> convertToEntityAttribute(String string) {
        return gson.fromJson(string, new TypeToken<List<Note>>(){}.getType());
    }
}


And here is the field on the entity side :
@Column(name = "note", columnDefinition = "text")
@Getter @Setter
private List<Note> notes;


I can persist the entity with notes just fine, the problem is when I want to merge the entity, then the 'notes' field is never updated on the database : I can not add notes to an already persisted entity, it does not even try to merge the entity as the optimist lock does not change.

Do you have any idea of what is happening ? Am I doing something wrong, is it supposed to be this way or is it a bug ?

Thank you !

[Updated on: Wed, 14 March 2018 05:23] by Moderator

Re: Attribute Converter not working properly on lists [message #1783606 is a reply to message #1783338] Wed, 14 March 2018 10:51 Go to previous messageGo to next message
Eclipse UserFriend
Your notes field mapping falls counts as a serializable mapping type and as per https://www.eclipse.org/eclipselink/documentation/2.4/concepts/app_dev005.htm#CCHBBHDH is considered immutable. For EclipseLink to know something has changed, you would have to create a new list, or mark the field as @Mutable for EclipseLink to know to check the field for changes.
Re: Attribute Converter not working properly on lists [message #1783703 is a reply to message #1783606] Thu, 15 March 2018 19:53 Go to previous message
Eclipse UserFriend
It makes a lot of sense and with the @Mutable annotation it now works.

Thank you so much !
Previous Topic:Shared Cache produce invalid 1-N elements that are not managed by entity manager
Next Topic:OrderColumn not respected in fetch of unidirectional OneToMan
Goto Forum:
  


Current Time: Wed Jul 23 21:19:11 EDT 2025

Powered by FUDForum. Page generated in 0.24422 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top