2017-10-13 1 views
-1

Il existe une table appelée Product (id, name). Chaque ligne du produit est un type de produit différent. Chaque produit a des données d'information différentes. Par exemple: Un produit comme "Internet" aura des données d'information "Plan actuel", "Numéro de compte", "Statut du compte", etc. Considérant que, un produit comme «Assurance» aura des données d'information «Bénéficiaire», «Bénéficiaire», «Dépôts totaux», «Total des réclamations» et ainsi de suite. Il existe une autre table appelée Customer like this.Héritage JPA: conception DB où chaque ligne d'une table correspond à une table dans Postgres

CREATE TABLE customer 
(
    id serial NOT NULL, 
    first_name text NOT NULL, 
    last_name text NOT NULL, 
    street_add text NOT NULL, 
    city text NOT NULL, 
    state text NOT NULL, 
    zip text NOT NULL, 
    phone text NOT NULL, 
    ssn text, 
    customer_since timestamp without time zone, 
    product_id integer NOT NULL, 
    intro_audio text NOT NULL, 
    search_params text, 
    verification_params text, 
    CONSTRAINT customer_pkey PRIMARY KEY (id), 
    CONSTRAINT fk_product_id FOREIGN KEY (product_id) 
     REFERENCES product (id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE NO ACTION 
) 

Je veux créer une table pour chaque produit: Par exemple, pour Internet:

CREATE TABLE internet_product_info 
(
    id serial NOT NULL, 
    customer_id integer NOT NULL, 
    current_plan text NOT NULL, 
    acc_type text NOT NULL, 
    acc_no text NOT NULL, 
    CONSTRAINT internet_product_info_pkey PRIMARY KEY (id), 
    CONSTRAINT fk_customer_id FOREIGN KEY (customer_id) 
     REFERENCES customer(id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE NO ACTION 
) 

Pour l'assurance:

CREATE TABLE insurance_product_info 
(
    id serial NOT NULL, 
    customer_id integer NOT NULL, 
    payee text NOT NULL, 
    beneficiary text NOT NULL, 
    total_deposits integer NOT NULL, 
    total_claims integer NOT NULL, 
    CONSTRAINT insurance_product_info_pkey PRIMARY KEY (id), 
    CONSTRAINT fk_customer_id FOREIGN KEY (customer_id) 
     REFERENCES customer(id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE NO ACTION 
) 

Je veux demander si cela est une bonne approche aller pour de tels scénarios ou il y a quelques meilleures options disponibles.

En java, je vais récupérer les propriétés du produit comme:

public class Customer implements Serializable{ 
    private int id; 
    private String firstName; 
    private String lastName; 
    private String streetAdd; 
    private String city; 
    private String state; 
    private String zip; 
    private String phone; 
    private String ssn; 
    private Date customerSince; 
    private Object internetProdInfo; 
    private Product product;  
} 

if(customer.getInternetProdInfo() instanceOf InternetProdInfo){ 
/* get the info for it*/ 
} 

En outre, comment puis-je charger dynamiquement ces champs de produits spécifiques à la page jsp dynamiquement.

+0

'CONTRAINTE fk_product_id FOREIGN KEY (product_id) n'existe pas. Il y a une colonne 'sim_product_id' (et je * pense * qu'elle ne devrait pas exister non plus) – joop

+0

J'ai renommé sim_product_id en product_id – Deepika

Répondre

0

Vous pouvez utiliser l'héritage java dans Hibernate comme vous l'avez mentionné ici. if(customer.getInternetProdInfo() instanceOf InternetProdInfo){ /* get the info for it*/ } ici nous pouvons avoir quelques liens que vous pouvez passer à travers ce n'est pas une solution simple, il a ses propres côtés, et beaucoup d'autres sont là.

  1. Documentation If You have Plenty of Time
  2. Blog Short and Helpful
  3. Another Blog Short and Helpful
  4. A Helpful Question
  5. Another Helpful Question
  6. https://stackoverflow.com
  7. Another Question

  8. Another Short Doc

    une superclasse mappé n'a pas de table distincte définie pour elle (utilisation @MappedSuperclass).

    informations de cartographie peut être surchargée dans ces sous-classes en utilisant les `` la colonne product_id` @AttributeOverride et @AssociationOverride annotations ou des éléments XML correspondant

+1

Shailesh Singh !! Merci beaucoup .. C'est exactement ce que je voulais .. – Deepika