Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:38 Go to next message
Sylvain Autran is currently offline Sylvain AutranFriend
Messages: 2
Registered: March 2018
Location: Paris, France
Junior Member
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 !


Payara 4.1.2.181

[Updated on: Wed, 14 March 2018 09:23]

Report message to a moderator

Re: Attribute Converter not working properly on lists [message #1783606 is a reply to message #1783338] Wed, 14 March 2018 14:51 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
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 23:53 Go to previous message
Sylvain Autran is currently offline Sylvain AutranFriend
Messages: 2
Registered: March 2018
Location: Paris, France
Junior Member
It makes a lot of sense and with the @Mutable annotation it now works.

Thank you so much !


Payara 4.1.2.181
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: Tue Mar 19 08:52:21 GMT 2024

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

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

Back to the top