-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mapping og address owned by two entity
PostPosted: Thu Sep 14, 2006 11:45 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.