-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: OneToMany on (filtered) DB view
PostPosted: Thu Feb 10, 2011 11:15 am 
Newbie

Joined: Thu Feb 10, 2011 9:50 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.