Hi Paolo, A few ideas:
1. Make use of callback annotations like @PrePersist and @PostLoad. 2. Make use of OpenJPA-specific annotations @Strategy or @Externalizer. See that forum discussion [1]. 3. Put the "if date == null" logic into getter and setter of the entities. However, since the entity enhancer modifies the getters and setters, your mileage may vary. See that forum discussion [2]. Hope this helps, Milosz [1] http://openjpa.208410.n2.nabble.com/Mapping-CHAR-column-to-String-tp5727930p5727930.html [2] http://openjpa.208410.n2.nabble.com/NPE-in-enhanced-entity-where-I-can-t-see-it-tp4986167p4986167.html > Hello, I use openjpa version openjpa-1.2.1-SNAPSHOT-r422266:686069, in a > legacy sistem. > There is a database DB2 with all tables with NOT NULL columns. > Instead of using null value, many cobol programmers (when they build the > database) uses space in varchar column or strange date (like 31-12-9999) in > date column. > > For example : > Table > --------------------------------- > |MyTable| > --------------------------------- > DATE NOT NULL|MY_DATE|9999-12-31 > --------------------------------- > VARCHAR(11) |MY_NAME|Paul > --------------------------------- > VARCHAR(11) |MY_SURNAME|Blond > --------------------------------- > > > @Entity > @Table(name = "MyTable") > public class MyEntity{ > ... > > @Column(name="MY_DATE", nullable="false") > private Date myDate; > ..... > } > > There is a method to map this table in a entity and when I write: > MyEntity ent = new MyEntity(); > ent.setMyDate(null); > .... > entityManager.persist(ent); > > in the sql insert script I found : > INSERT INTO MyTable(..,MY_DATE,..) VALUES(..., 9999-12-31,..) > instead of > INSERT INTO MyTable(..,MY_DATE,..) VALUES(..., NULL,..) > > ?? > > In practice, can JPA replace a NULL value with another value? > You must consider that I want the same behaviour when I do a getMyDate() (if > in db there is a date 9999-12-31, MyEntity.myDate = null instead of > 9999-12-31). > > Thank in advance > Paolo >
