-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problme mit mapping tabelle
PostPosted: Tue Sep 12, 2006 4:27 am 
Newbie

Joined: Wed Jun 21, 2006 9:48 am
Posts: 12
Location: Germering
ER-Diagramm
Code:
+-----------+ 1      n +-------------------+ n      1 +------------+
|   person  | ---<>--- |   personaddress   | ---<>--- |   address  |
+-----------+          +-------------------+          +------------+
| person_id |          | person_id     (fk)|          | address_id |
| firstname |          | address_id    (fk)|          | street     |
| lastname  |          | addresstype_id(fk)|          | zip        |
+-----------+          +-------------------+          | country    |
                                |n                    +------------+
                                |
                                |
                                |                   1 +---------------+
                                +-------------<>----- |  addresstype  |
                                                      +---------------+
                                                      | addresstype_id|
                                                      | addresstpye   |
                                                      +---------------+

Daten aus der Tabelle "addresstype": 'private', 'office primary', 'office secondary'

Ich speichere den addresstyp nicht in der addresse, weil die private adresse auch die büro adresse sein könnte, oder weil
die firmenanschrift des einen die Firmen und Privatanschrift eines anderen sein könnten.

Wenn ich mir nun alle daten aus der Datenbank holen will nutze ich flgendes SQL-Statement:
Code:
select p.firstname, p.lastname, a.street, a.zip, a.country, a. addresstype
    from person as p
    join personaddress as pa on p.person_id = pa.person_id
    join address as a on pa.address_id = a.address_id
    join addresstype at on pa.addresstype_id = at.addresstype_id;

Meine Java Klassen dazu schauen so aus:
Code:
class Person {
    private long id;
    private String firstname;
    private String lastname;
    private List addresses;
   
    /** def c-tor */
    /** getter and setter */
}

class Address {
    private long id;
    private String street;
    private String zip;
    private String city;
    private String country;

    /** def c-tor */
    /** getter and setter */
}

Meine Frage lautet nun:"Wie muss ich meine hbm.xml Dateien konfigurieren, dass die Daten richtig geladen werden und ich die Daten sowohl laden, löschen, aktualisieren oder einfügen kann?"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 6:50 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Ich würde zu Collection und Component Mapping in der Hibernate Reference nach den Beispielen gucken.

Evt. kannst Du die Adresse auch über eine "formular" leichter identifizieren. Einfach nach dem Keyword in der Referenze suchen.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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

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.