Reputation: 1845
I've created a project with maven on netbeans. after defining the tables in mySql program i'm trying to generate the entity classes from database, using the Netbeans IDE.
The thing is that I have a table Cage and a table Animal and i wnat it to be a one to one relationship, but when i generate the entities the IDE put it as a one to many relationship (with the anotattions).
I think that my tables, in the database, are well created What am i doing wrong? How can i fix this problem?
Upvotes: 0
Views: 558
Reputation: 64039
There are three cases where a @OneToOne
would be used by a DB schema reverse engineering tool:
The associated entities share the same primary keys values
A foreign key is held by one of the entities and this FK column in the database has a unique constraint in order to emulate one-to-one multiplicity
An association table is used to store the link between the 2 entities (a unique constraint has to be defined on each FK to ensure the one to one multiplicity).
If your tables do not have one of the aforementioned characteristics @OneToMany
will be used.
Check out this tutorial for more details (that is where the three aforementioned cases are from)
Upvotes: 1