I'm using JPA and Hibernate (Core version = 3.5.4-Final)
What worked so far:Two entities A and B with a unidirectional one-to-many relationship from A to B.
Code:
@Entity
@Table
public class A {
// ommitting id definition
@OneToMany(cascade = CascadeType.ALL))
@JoinColumn(name = "a_id")
private List<B> bs;
...
}
@Entity
public class B {
// ommitting id definition
...
}
The generated schema consists of two tables
A (...)
and
B (..., a_id)
Desired change:Now I need to filter the list of B's in A (but not in some other place) and therefore I introduced a DB view like this
Code:
create or replace view filtered_B as
select * from B
where <some filter condition>;
So far so good, the view is created correctly and contains exactly those rows that I'm interested in.
Problem:In order to switch from the table B to the view filtered_B on A's one-to-many relationship, I tried to add the table name like this
Code:
@OneToMany(cascade = CascadeType.ALL))
@JoinColumn(table = "filtered_B", name = "a_id")
private List<B> bs;
But this results in the following exception:
Code:
org.hibernate.cfg.NotYetImplementedException: Collections having FK in secondary table
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1831)
I only found two posts that seemed to be related, one of them (
viewtopic.php?p=2429441) did not receive any responses, the other (
viewtopic.php?p=2367398) just one that wasn't really helpful - I mean what was emmanuel exactly meaning with
Quote:
you can change the DDL manually
?
So the questions are:
- is what I try to do possible at all using JPA/Hibernate?
- or are there any alternatives?
As always, any hints welcome!
Cheers
pat