-->
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: Verknüpfung zweier Tabellen
PostPosted: Wed Aug 03, 2011 4:30 am 
Newbie

Joined: Wed Aug 03, 2011 3:52 am
Posts: 1
Moin,
ich habe folgendes Problem. Ich haben 2 Tabellen, die ich verknüpfen will. Die ID der ersten Tabelle soll die gleiche wie in der zweiten Tabelle sein. Die zweite Tabelle soll LAZY geladen werden.

Tabelle 1 "cus_migration_data":
    id | spalte1 | spalte2
    --+--------+--------
    1 | text | text
    2 | text | text
    3 | text | text

Tabelle 2 "migration_protocol":
    id | protokoll
    --+----------
    1 | protokoll1
    2 | protokoll2
    3 | protokoll3

Ich weiß jetzt nicht wie ich diese beiden Tabellen per Hibernate verknüpfe, so dass immer wenn ein User[id = 2] ein Protokoll anfordert in Tabelle2 unter der entsprechenden ID das Protokoll geladen wird.

So sieht die Bohne von Tabelle1 aus
Code:
@Entity
@Table(name = "cus_migration_data")
@Filters({ @Filter(name = "archiv"), @Filter(name = "owner") })
@SecondaryTables({ @SecondaryTable(name = "migration_protocol") })
public class MigrationVO extends StampedVO {

    private static final long serialVersionUID = -3753431498845324015L;

    /** maximale Länge der Begleitermailadresse */
    private static final int EMAIL_LEN = 200;

    @Column(name = "probelauf")
    private boolean probelauf;

    @Column(name = "step_basis_cus_nr", nullable = false)
    private String stepBasisKundenNr;

    @Column(name = "typ", nullable = false)
    @Enumerated(EnumType.STRING)
    private MigrationDomainType typ;

    @Column(name = "protokoll_name", nullable = false)
    private String protokollName;

 
    !!! private MigrationProtokollVO protokoll; !!! <- das ist das Feld für Tabelle 2

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "linked_cusid", nullable = false)
    private KundeVO kunde;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_migration_data_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @Filters({ @Filter(name = "archiv"), @Filter(name = "owner"), @Filter(name = "export") })
    private MigrationVO parentMigration;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentMigration")
    @Filters({ @Filter(name = "archiv"), @Filter(name = "owner") })
    @Cascade(org.hibernate.annotations.CascadeType.DELETE)
    private final List<MigrationVO> subMigrationen = new ArrayList<MigrationVO>();

    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "createdby", updatable = false, insertable = false)
    private BenutzerVO migriertVon;

    @Column(name = "email_csv", nullable = false)
    private String emailCSV;

    @Column(name = "email_mig_begleiter", nullable = false, length = EMAIL_LEN)
    private String emailMigrationsBegleiter;

    @OneToMany(mappedBy = "migrationData", fetch = FetchType.LAZY)
    @Filters({ @Filter(name = "archiv"), @Filter(name = "owner"), @Filter(name = "export") })
    @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
    private final List<TeilnehmerMigrationVO> teilnehmerMigrationData = new ArrayList<TeilnehmerMigrationVO>();

    @OneToMany(mappedBy = "migration", fetch = FetchType.EAGER)
    @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
    private final List<DomainParameter> parameter = new ArrayList<DomainParameter>();


Und dies ist die Bohne zu Tabelle2:
Code:
public class MigrationProtokollVO implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1460009823592438889L;

    @Column(name = "protokoll", table = "migration_protocol")
    private String protokoll;

    public final String getProtokoll() {
        return protokoll;
    }

    public final void setProtokoll(final String protokoll) {
        this.protokoll = protokoll;
    }


Das MigrationProtokollVO ist noch nicht vollständig, da ich nicht weiß wie ich weitermachen soll....

Hoffe ihr könnt mir helfen.

gruß mb


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.