Two tables A
and B
. B
has a NOT NULL foreign key (many-to-one) which points to A
. There is no columns in A
, which tells, the table B
exists. That means the relation is one-way
Created POJO classes A
and B
with Eclipse hibernate tools reverse enginnering. The class B
has a property with type A
, which is correct.
But, why the class A
has a property as List<B>
, even if the relationship defined is not two-way.
Is this for any advantage in development or is this the way, how reverse engineering works ?
If there is more table C,D,E...
has same relation to A
, the class A
will have that much List<?>
variables and I think it doesn't look nice. Is there any way to avoid this?
Eclipse JPA tools are designed to create a double sided relationship when they find a foreign-key from a table to another; I have no references of this, which is an empirical deduction based on many years of Eclipse use.
This behavior is quite common: Eclipse creates for you a @ManyToOne
field on class B
, which is the owning side of the relation, and @OneToMany
field on class A
, which is the dependent side of the relation. This means that you need to operate on the owning side, if you want any change to be saved to the database; and this also means you can delete that field, if you do not need it.
AFAIK you can not tell Eclipse to avoid create the dependent sides, you have to delete them yourself.