Attribute Converter not working properly on lists [message #1783338] |
Mon, 12 March 2018 08:38 |
Sylvain Autran 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02264 seconds