Hibernate Books

All times are UTC - 5 hours [ DST ]

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to write Annotations for composed keys (and Join them)
PostPosted: Tue Jun 19, 2012 1:51 am 

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:

public class FilialKontakt implements Serializable {

    private static final long serialVersionUID = -3669314898011844021L;

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

public class Adressliste {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ADRESSLISTEID")     
    private Integer adresslisteid;
    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:
@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.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.