Hello,
i'm using JBoss AS 4.2.3.GA.
I have an Entity Schmelze with two One-To-One bidirectional relationships SollSchmelze and VerlustSchmelze which have an embedded Attribut PlanungsNummer:
Code:
@Entity
public class Schmelze implements Serializable {
...
private SollSchmelze sollSchmelze;
private VerlustSchmelze verlustSchmelze;
...
@OneToOne(mappedBy="schmelze", optional = true)
public SollSchmelze getSollSchmelze() {
return sollSchmelze;
}
@OneToOne(mappedBy="schmelze", optional = true)
public VerlustSchmelze getVerlustSchmelze() {
return verlustSchmelze;
}
...
}
@Entity
public class SollSchmelze implements Serializable {
...
private Schmelze schmelze;
private PlanungsNummer planungsNummer;
...
@Embedded
public PlanungsNummer getPlanungsNummer() {
return planungsNummer;
}
@OneToOne(optional = true)
@JoinColumn(name = "schmelze_id")
public Schmelze getSchmelze() {
return schmelze;
}
...
}
@Entity
public class VerlustSchmelze implements Serializable {
...
...
private Schmelze schmelze;
private PlanungsNummer planungsNummer;
...
@Embedded
public PlanungsNummer getPlanungsNummer() {
return planungsNummer;
}
@OneToOne(optional = true)
@JoinColumn(name = "schmelze_id")
public Schmelze getSchmelze() {
return schmelze;
}
...
}
@Embeddable
public class PlanungsNummer implements Serializable {
...
private int nummer;
...
}
I want to select an Schmelze-entity with a relation to an SollSchmelze-entity with a specific PlanungsNummer. OR with a relation to an VerlustSchmelze-entity with a specific PlanungsNummer.
For this, i created the following EJB-QL statement:
Code:
SELECT
OBJECT(s)
FROM
Schmelze AS s
WHERE
(
(
s.sollSchmelze IS NOT NULL
AND s.sollSchmelze.planungsNummer.nummer = :planungsnummer1
)
OR (
s.verlustSchmelze IS NOT NULL
AND s.verlustSchmelze.planungsNummer.nummer = :planungsnummer2
)
)
ORDER BY
s.entstehung DESC
Hibernate generate this SQL statement:
Code:
select
schmelze0_.id as id41_,
schmelze0_.nummer as nummer41_,
schmelze0_.kennungGiessAnlage as kennungG3_41_,
schmelze0_.entstehung as entstehung41_,
schmelze0_.pfanne_id as pfanne6_41_,
schmelze0_.spaeteErzZugabe as spaeteEr5_41_
from
Schmelze schmelze0_,
SollSchmelze sollschmel1_,
VerlustSchmelze verlustsch2_
where
schmelze0_.id=sollschmel1_.schmelze_id
AND schmelze0_.id=verlustsch2_.schmelze_id
and (
(
schmelze0_.id is not null
)
and sollschmel1_.nummer=?
or (
schmelze0_.id is not null
)
and verlustsch2_.nummer=?
)
order by
schmelze0_.entstehung DESC limit ?
This would always result in an empty resultlist, because the Schmelze never is a SollSchmelze and a VerlustSchmelze.
I'd expected something like:
Code:
...
where
schmelze0_.id=sollschmel1_.schmelze_id
OR schmelze0_.id=verlustsch2_.schmelze_id
and (
How i have to change the EJB-QL statement to achieve the correct ResultList?
Thx
Ludger