Hi
We have a problem with Hibernate filters in JBoss AS 7.2. It seems to me that this may be a bug. But it is also possible that i miss something.
Our data model has entities and requests for these entities. The table structure is like the following:
Code:
TABLE MY_ENTITY
MY_ENTITY_ID VARCHAR(20)
....
TABLE REQUEST
REQUEST_ID NUMBER(10)
REQUEST_ENTITY VARCHAR(10)
REQUEST_STATE VARCHAR(10)
...
TABLE MY_ENTITIY_REQUEST
REQUEST_ID NUMBER(10)
MY_ENTITY_ID VARCHAR(20)
...
In the Java code this results in the following JPA entities:
Code:
@Entity
@Table(name="MY_ENTITY")
public class MyEntity implements Serializable {
@Column(name="MY_ENTITY_ID")
@Id
private String name;
....
}
@Entity
@Table(name="REQUEST")
public abstract class Request implements Serializable {
@Column(name="REQUEST_ID")
@Id
private Long id;
@Column(name="REQUEST_STATE")
private String requestState;
....
}
@Entity
@Table(name="MY_ENTITY_REQUEST")
public class MyEntityRequest extends Request implements Serializable {
@Column(name="MY_ENTITY_ID")
private String myEntityId;
....
}
In the MyEntity class we now need a list of filtered requests (filtered by REQUEST_STATE). We tried this with hibernate filters:
Code:
@Entity
@Table(name="MY_ENTITY")
@FilterDefs({
@FilterDef(name="openRequest")
})
@Filters({
@Filter(name="openRequest", condition="{h}.REQUEST_STATE <> 'DONE'", aliases={@SqlFragmentAlias(alias="h", table="REQUEST")})
})
public class MyEntity implements Serializable {
....
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="MY_ENTITY_ID")
@Filters({
@Filter(name="openRequest", condition="{h}.REQUEST_STATE <> 'DONE'", aliases={@SqlFragmentAlias(alias="h", table="REQUEST")})
})
private Set<MyEntityRequest> openRequests;
}
Unfortunately this results in an exception:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "OPENREQUES4_1_"."REQUEST_STATE": ungültiger Bezeichner
I debugged the resulting SQL and found the the where clause is placed wrongly:
Code:
select *
from MY_ENTITY myEntity0_
left outer join MY_ENTITY_REQUEST openreques4_ on myEntity0_.MY_ENTITY_ID=openreques4_.MY_ENTITY_ID and openreques4_1_.REQUEST_STATE <> 'DONE'
left outer join REQUEST openreques4_1_ on openreques4_.REQUEST_ID=openreques4_1_.REQUEST_ID where myEntity0_.MY_ENTITY_ID=?
Is this a bug or do i miss something?
Thanks in advance
Christian