openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Spiro" <m.sp...@dcs-caesar.de>
Subject Re: Defining Where clause on OneToMany Association, Why is there no @Where Annotation ?
Date Mon, 05 Dec 2011 09:19:17 GMT
Hi,

according to the documentation (Part 3, chapter 7, paragraph 6 "Non-Standard
Joins") there should be an "official" option for a join with a constant
value in a specified column. The constant value should be specified in the
attribute "referencedColumnName" of the @JoinColumn annotation (with a
special grammatical trick allowing to tell a constant value from a regular
column name). However, due to a bug it doesn't work properly (see the JIRA
issues OPENJPA-1979 and OPENJPA-2054). Let's hope that this will work in
future releases. However, the documentation says that the constant values
can be strings, numeric or null, but nothing about boolean constants.

By the way, I wonder why this is called "non-standard join". IMHO, this kind
of join is a rather common case.

Kind regards,
Michael Spiro

> -----Urspr√ľngliche Nachricht-----
> Von: Tobias Trelle [mailto:tobias.trelle@codecentric.de]
> Gesendet: Montag, 5. Dezember 2011 09:06
> An: users@openjpa.apache.org
> Betreff: Re: Defining Where clause on OneToMany Association, Why is
> there no @Where Annotation ?
> 
> Hi Sebastian,
> 
> there is no @Where annotation. You have to use a custom JPQL query like
> this:
> 
> @Entity
> @Table(name = "naviglobal")
> *@NamedQuery(name="getDeleted" query = "SELECT ng FROM Naviglobal ng
> LEFT
> JOIN ng.mainnavi mn WHERE mn.deleted = true")
> *public class *Naviglobal* implements Serializable {
> ...
>     @OneToMany(*fetch = FetchType.LAZY*)
>     @JoinColumn(name="global_id")
>     private List<Navimain> mainnavi;*
> ...
> 
> Somewhere in your service / DAO / or whatever:
> 
> TypedQuery<Naviglobal> q = em.createNamedQuery("getDeleted",
> Naviglobal.class);
> List<Naviglobal> result = q.getResultList();
> 
> HTH,
> Tobias
> 
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Defining-Where-clause-on-OneToMany-
> Association-Why-is-there-no-Where-Annotation-tp6994016p7062094.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message