Using Play! framework and it's JPASupport class I have run into a problem with a legacy database.
I have the following class:
@Entity
@Table(name="product_catalog")
public class ProductCatalog extends JPASupport {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer product_catalog;
@OneToOne
@JoinColumn(name="upper_catalog")
public ProductCatalog upper_catalog;
public String name;
}
Some product catalogs don't have an upper catalog, and this is referenced as 0 in a legacy database. If I supply the upper_catalog as NULL, then expectedly JPA inserts a NULL value to that database column. How could I force the null values to be 0 when writing to the database and the other way around when reading from the database?