Hallo,
ich versuche hier eine Tabelle zweimal zu joinen, aber leider taucht im Ergebnis nur der letzte join auf.
Hier ein Beispiel:
Ich habe zwei Tabellen:
text und translation.
text referenziert zweimal translation, einmal durch 'foo' und einmal durch 'bar'.
So sieht mein Versuch aus:
Mit dem Erfolg das foo immer null bleibt. Der Hibernate Debug-Log zeigt, dass das Feld 'foo' ignoriert wird und die Tabelle translation nur einmal gejoined wird.
Und hier einmal als SQL was ich eigentlich erwartet haette:
[sql]select text.oid, translation_0.text, translation_1.text, text.moep
from (
select 200 as oid,
100 as foo,
101 as bar,
'a value' as moep
union
select 201 as oid,
102 as foo,
103 as bar,
'another value' as moep
) text
left outer join (
select 100 as tid,
'first value' as text
union
select 101 as tid,
'second value' as text
union
select 102 as tid,
'third value' as text
union
select 103 as tid,
'fourth value' as text
) translation_0 on translation_0.tid = text.foo
left outer join (
select 100 as tid,
'first value' as text
union
select 101 as tid,
'second value' as text
union
select 102 as tid,
'third value' as text
union
select 103 as tid,
'fourth value' as text
) translation_1 on translation_1.tid = text.bar[/sql]
Vielen Dank.
ich versuche hier eine Tabelle zweimal zu joinen, aber leider taucht im Ergebnis nur der letzte join auf.
Hier ein Beispiel:
Ich habe zwei Tabellen:
text und translation.
text referenziert zweimal translation, einmal durch 'foo' und einmal durch 'bar'.
So sieht mein Versuch aus:
Java:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Translation {
@Id
private Long tid;
private String text;
}
Java:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Text {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequence")
@SequenceGenerator(name="sequence", sequenceName="seq_oid")
protected Long oid;
@ManyToOne(optional = true)
@JoinTable(name = "Translation",
joinColumns = {
@JoinColumn(name = "tid")
},
inverseJoinColumns = {
@JoinColumn(name="foo")
}
)
protected Translation foo;
@ManyToOne(optional = true)
@JoinTable(name = "Translation",
joinColumns = {
@JoinColumn(name = "tid")
},
inverseJoinColumns = {
@JoinColumn(name="bar")
}
)
protected Translation bar;
protected String moep;
}
Mit dem Erfolg das foo immer null bleibt. Der Hibernate Debug-Log zeigt, dass das Feld 'foo' ignoriert wird und die Tabelle translation nur einmal gejoined wird.
Und hier einmal als SQL was ich eigentlich erwartet haette:
[sql]select text.oid, translation_0.text, translation_1.text, text.moep
from (
select 200 as oid,
100 as foo,
101 as bar,
'a value' as moep
union
select 201 as oid,
102 as foo,
103 as bar,
'another value' as moep
) text
left outer join (
select 100 as tid,
'first value' as text
union
select 101 as tid,
'second value' as text
union
select 102 as tid,
'third value' as text
union
select 103 as tid,
'fourth value' as text
) translation_0 on translation_0.tid = text.foo
left outer join (
select 100 as tid,
'first value' as text
union
select 101 as tid,
'second value' as text
union
select 102 as tid,
'third value' as text
union
select 103 as tid,
'fourth value' as text
) translation_1 on translation_1.tid = text.bar[/sql]
Vielen Dank.