Bug 484610 - @Convert conversion does not get applied when retrieving the newly persisted entity.
Summary: @Convert conversion does not get applied when retrieving the newly persisted ...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-17 15:36 EST by Patrick Lee CLA
Modified: 2022-06-09 10:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Lee CLA 2015-12-17 15:36:21 EST
I have an entity with an @Convert annotation on a field and the conversion is getting run and it persists to the database properly.  When retrieving that newly persisted value the Pojo coming back does not have the converted value.  If I clear the cache before retrieving the value is correct.  Is this some kind of caching configuration issue on my end or a bug with @Converter and caching ? 

Here is some pseudo code:

@Converter
public class EmptyStringToNull implements AttributeConverter <String, String> {
    @Override
    public String convertToDatabaseColumn(String v) {
        return Strings.emptyToNull(v);
    }

    @Override
    public String convertToEntityAttribute(String v) {
        return Strings.emptyToNull(v);
    }
}

@Entity
public class Model {

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getValue() {
        return value;
    }

    public void setId(String value) {
        this.value = value;
    }

    @Id
    @Column(name="id")
    private Long id;

    @Convert(converter = EmptyStringToNull.class)
    @Column(name="value")
    private String value;
}

Model m = new Model();
m.setId(1);
m.setValue("");
em.persist(m);
em.find(Entity.class, 1).getValue() //returns ""

...
em.persist(m);
getEntityManagerFactory().getCache().evictAll();
em.find(Entity.class, 1).getValue() //returns null
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:10:25 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:16:03 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink