Is it possible to store a Java DSL object with JPA?
I have a Java DSL object i.e. POJO that returns this
in setters and 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;
}
}
Can JPA be told to use "name (String)" and "name ()" as setter / getter method?
[EDIT] My problem is the field created
above. For this field, I want JPA to use a "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
?
a source to share
According to the JPA specification (see JSR-220 ) in chapter 2.1.1, you can tell JPA to use field access instead of property access by annotating fields to display information rather than getter methods.
I don't think you can tell JPA what naming convention to use for getters and setters as this is the basic concept of java beans.
a source to share