Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.2CR4
I've one question or dubt about the correct mapping of this entity.
I've this business objects:
Code:
/**
* @author Filippo De Luca
* @version 1.0.00
*/
public class Address {
private Long id;
private Paese paese;
private Provincia provincia;
private String comune;
private String cap;
private String indirizzo;
/* ... */
}
/**
* @author Filosganga
* @version 1.0.00
*/
public class Employee implements PropertyChangeListener {
private Long id;
private String surname;
private String name;
private Gender sesso;
private Address indirizzo;
/* ... */
}
/**
* @author Filippo De Luca
* @version 0.1.00
*/
public class Supplier implements PropertyChangeListener {
private Long id;
private String ragioneSociale;
private String partitaIva;
private Address indirizzo;
/* ... */
}
the mapping is: A supplier have one-to-one relation with Address, and also the Employee have one-to-one relation with Address. But address have one-to-one relation with a employee XOR with a Supplier.
So my dubt is overe the db schema what is better:
Suppose I have this two table:
Code:
CREATE TABLE `supplier` (
spl_id INT PRIMARY KEY,
spl_name VARCHAR(40),
spl_surname VARCHAR(60),
...
)
CREATE TABLE `employee` (
emp_id INT PRIMARY KEY,
emp_name VARCHAR(40),
emp_surname VARCHAR(60),
...
)
For mapping the address which of the follow solutions is better an why:
1) mapping relations in the same table of address
Code:
CREATE TABLE `address` (
add_id INT PRIMARY KEY,
add_comune VARCHAR(60),
...
spl_id INT,
emp_id INT
)
2) mapping relations in a separate table
Code:
CREATE TABLE `address` (
add_id INT PRIMARY KEY,
add_comune VARCHAR(60),
...
)
CREATE TABLE `address_relations` (
add_id INT PRIMARY KEY,
spl_id INT,
emp_id INT,
)
3) mapping relations in ono table per relation
Code:
CREATE TABLE `address` (
add_id INT PRIMARY KEY,
add_comune VARCHAR(60),
...
spl_id INT,
emp_id INT
)
CREATE TABLE `address_suppliers` (
add_id INT PRIMARY KEY,
spl_id INT
)
CREATE TABLE `address_employee` (
add_id INT PRIMARY KEY,
emp_id INT
)
I'm glade to anyone can help me.