-->
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: How to write Annotations for composed keys (and Join them)
PostPosted: Tue Jun 19, 2012 1:51 am 
Newbie

Joined: Mon Jun 18, 2012 7:54 am
Posts: 6
Hi there.
I've got a Problem with composed keys in Hibernate.
Here is my current structure:

Code:
@Entity
@Table(name="FILIALKONTAKT")
public class FilialKontakt implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -3669314898011844021L;

    @Id
    @ManyToOne(fetch=FetchType.EAGER,cascade = CascadeType.PERSIST)
    @JoinColumn(name = "FILIALID", insertable=true, updatable=true)     
    private Filiale myFiliale;
   
    @Id
    @ManyToOne(fetch=FetchType.EAGER,cascade = CascadeType.PERSIST)
    @JoinColumn(name = "KONTAKTID", insertable=true, updatable=true)   
    private Kontakte myKontakt;
   
    @Column
    private Integer primaerKz;
   
    public FilialKontakt() {
       
    }
//nachfolgend getter und setter


Code:
@Entity
@Table(name="ADRESSLISTE")
public class Adressliste {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ADRESSLISTEID")     
    private Integer adresslisteid;
   
    @Column(name="BEZEICHNUNG")
    private String  bezeichnung;
   
    public Adressliste() {
       
    }
//nachfolgend getter und setter


Now I want to make a Table wich contains the "AdresslistID", "FilialID" and the "KontaktID" as primary Key.
My Problem is, that i doesn't know, how to handle the composed keys and how to join them.

In another part I have this structure:
Table: Filiale(ID (PK), Name)
Table: Branche(ID (PK), Name)

and the "Help"-Table: Tabelle FilialBranche(FilialID(PK/FK), BrancheID(PK/FK))
And my (working) Annotations looks like this:
Code:
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name="FILIALBRANCHE", joinColumns = {
      @JoinColumn(name="FILIALID") }, inverseJoinColumns = {
      @JoinColumn(name="BRANCHEID") } )
private Set <Branche> myBranche = new HashSet<Branche>(0);


But this doesn't work for my first structure.
I hope you understand my Problem and I also hope, that my english is not that bad.


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.