0
votes

I have a DSL Java object, i.e. a POJO which returns this in setters plus the getters/setters have an unusual naming pattern:

public class Demo {
    private long id;
    private String name;
    private Date created;

    public Demo id (long value) { id = value; return this; }
    public String id () { return id; }
    public Demo name (String value) { name = value; return this; }
    public String name () { return name; }
    public Demo created (Date value) { created = value; return this; }
    public Date created () { 
        if (created == null) created = new Date ();

        return created;
    }

}

Is it possible to tell JPA to use "name(String)" and "name()" as the setter/getter method?

[EDIT] My issue is the created field above. For this field, I want JPA to use the "getter" created() so the field will always be non-NULL.

Or is there a way to tell JPA to use CURRENT TIMESTAMP when creating a new object with created == null?

2

2 Answers

0
votes

According to the JPA spec (see JSR-220) chapter 2.1.1 you can tell JPA to use field access instead of property access by annotating the fields for mapping information and not the getter methods.

I don't think you can tell JPA which naming convention to use for getters and setters since it's a basic java beans concept.

0
votes

Could you not simply intialise created when you define in the class, and then use field access.

private Date created = new Date();