Instead of a virtual entity, you could create the view and tell OpenJPA about the view via @JoinTable annotations...
On Thu, Jun 24, 2010 at 5:07 AM, Daryl Stultz <[email protected]> wrote: > Hello, > > I've get a many-to-one relationship between tables A and E. E is a "loose" > association of A. There is no foreign key in A pointing to E. The > relationship is via tables B, C, and D. In SQL, working out this > relationship is pretty easy, just joining in the intermediate tables and > selecting the values from A and E. I can't use this approach in JPQL, > though, since I can't join or filter as there's no physical relationship. > I'd like to create a view and write an entity to model the view instead of a > table. The problem is that there's no primary key of this "Virtual Entity" > nor any compound key that can be formed. So obviously I can't load in this > entity as the Persistence Context and caches would not be happy. I'm > wondering if I can pick an arbitrary (non-unique) column and label it the > primary key just to get enhancing to work, then reference the entity in > queries. Something like this: > > select o.e from MyVirtualEntity o > where o.a = :a > > Will this work? > > Thanks. > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > http://www.opentempo.com > mailto:[email protected] > -- mailto:[email protected] skype:matthewadams12 yahoo:matthewadams aol:matthewadams12 google-talk:[email protected] msn:[email protected] http://matthewadams.me http://www.linkedin.com/in/matthewadams
