I am using EclipseLink as my JPA implementation and Postgresql as my DB.


        @Table(name="\"XYZ\"", schema="\"XYZ\"")
        @NamedQuery(name="XYZ.findAll", query="SELECT r FROM XYZ r")
        public class XYZ implements  Serializable {
            private static final long serialVersionUID = 1L;

            private String resourceID;

            @Array(databaseType = "text")
            private List<String> label;

            // getter/setters 


I have a requirement such that for every List attribute in my JPA, whenever it's value is null, I want to save the list as of size 1 with first element set to null.

null-----> [null]

Then, unset it backwards while retrieving back i.e if list is coming as [null] set it to null and give back to the user.

[null]-----> null

Currently I can think of this approach of editing every getter/setter of List type, to set/unset the above requirement. Something like this

    public List<String> getLabels() {
        return unset(this.labels);

    public void setLabels(List<String> labels) {
        this.labels = set(labels);

Here, set & unset add the above list with first element null and reverse.

Is there a cleaner approach to this ?? With this I have to edit every gett/sett of List type which is a little cumbersome.

I could not find any annotations in EclipseLink directly for this to edit a value before persisting.

Any help would be appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.