Hallo zusammen,

ich habe hier ein kleines Problem:

In zwei Tabellen muss ich eine composite-id benutzen, da es sonst keinen unique key in der struktur gibt.

Die Klassen der Composite-Ids sind serialziable und überschreiben hashcode() und equals. Es funktioniert auch alles so, mein Problem bzw mein Wunsch wäre zu wissen:

Wie erhalte ich das entsprechende Object, wenn eine Composite-ID benutzt wird?
Der normale Weg ist ja: Session.get() oder Session.load()

Das scheint aber so nicht zu funktionieren.

Hier mal meine Mapping File:
Code java:
1
2
3
4
5
6
7
8
9
10
11
12
 <composite-id name="tbl01Id" class="de.test.hibernate.Tbl01Id">
            <key-property name="apfinr" type="int">
                <column name="APFINR" length="7" />
            </key-property>
            <key-property name="aplfnr" type="int">
                <column name="APLFNR" length="6" />
            </key-property>
        </composite-id>
        <property name="aplkz" type="int">
            <column name="APLKZ" precision="1" scale="0" />
        </property>
      ....

Tbl01Id.java
Code java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
public classTbl01Id implements Serializable {
 
    private int id;
    private int apfinr;
    private int aplfnr;
    
    public Tbl01Id() {
 
    }
 
    public Tbl01Id(int id, int apfinr, int aplfnr) {
        this.apfinr = apfinr;
        this.aplfnr = aplfnr;
        this.id = id;
    }
 
    public int getApfinr() {
        return this.apfinr;
    }
 
    public void setApfinr(int apfinr) {
        this.apfinr = apfinr;
    }
 
    public int getAplfnr() {
        return this.aplfnr;
    }
 
    public void setAplfnr(int aplfnr) {
        this.aplfnr = aplfnr;
    }
    
    public int getId() {
        return this.id;
    }
    public void setId() {
        int i = apfinr + aplfnr;
        id = i;
    }
 
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + apfinr;
        result = prime * result + aplfnr;
        result = prime * result + id;
        return result;
    }
 
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Tbl01Id other = (Tbl01Id) obj;
        if (apfinr != other.apfinr)
            return false;
        if (aplfnr != other.aplfnr)
            return false;
        if (id != other.id)
            return false;
        return true;
    }
}

Meine Frage geht das überhaupt? Oder ist etwas an der Tbl01Id Klasse falsch?

Danke fürs Lesen.