Hi,
I'm currently writing an application which uses an already existing database. One of the more challenging parts regarding this is that we don't want to change the database and this has caused a few problems. In this database most of the columns are not allowed to have the value null. This also includes foreign key columns. When a foreign key column does not refer to another entity, 0 is used instead of null. How do I map my entities so that 0 means the same as null?
Example:
We have a table which maps a tree structure. Which means that each entity has zero or one parent and zero or more children. The root in each tree doesn't have a parent and therefore the parent id is 0. This is a bi-directional one-to-many/many-to-one relationship. See example code below:
[i]public class CategoryBean {
...
@ManyToOne
@JoinColumn(name = "parent_id")
private CategoryBean parent;
@OneToMany(mappedBy = "parent")
private Set<CategoryBean> children = new HashSet<CategoryBean>();
...
[/i]
Is there a solution to my problem or do we have to change the database and all its entities?
Thank you for the help!
/Leo
[Message sent by forum member 'woel' (woel)]
http://forums.java.net/jive/thread.jspa?messageID=239271