Hi there,
i am trying to join one table two times, but for some reason there is only the second one in the result.
Here is an example:
I have two tables:
text and
translation.
text contains two fields referencing
translation ('foo' and 'bar').
Here is my attempt:
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Translation {
@Id
private Long tid;
private String text;
}
Code:
@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;
}
But what I expected to get is something like this:
Code:
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
Any would be greatly appreciated.
Update:By replacing the annotation
Code:
@ManyToOne(optional = true)
@JoinTable(name = "Translation",
joinColumns = {
@JoinColumn(name = "tid")
},
inverseJoinColumns = {
@JoinColumn(name="foo")
}
)
by this
Code:
@ManyToOne(optional = true)
@JoinColumn(name = "foo")
everything seems to be fine.