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

Reply via email to