Thanks very much Patrick. Please see my comments inline.

Patrick Linskey-2 wrote:
> 
> Regarding q2: em.merge() should do the trick.
> 
> [Frank Le] I don't want to merge since the entity is not immutable and I
> want the state of the instance from the database, and I *guess* contains()
> will be more efficient than refresh(). Is it true that contains() in
> general more efficient than refresh() or merge() regardless the difference
> behavior?
> 
> Also, IIRC, your case 1 should always fail; maybe we should make it
> throw instead since that's a pretty convoluted way to always return no
> results.
> 
> [Frank Le] I totally agree, since this behavior is not in the spec or
> OpenJPA manual, this will cause lot of debug from developers.
> 
> -Patrick
> 
> On 9/17/07, frankca <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> I have simple query with Foo and FooType are persistent classes and name
>> is
>> string type:
>> (1)    @NamedQuery(
>> (2)        name = "Foo.findByTypeAndName",
>> (3)        query = "SELECT e " +
>> (4)                "FROM Foo e " +
>> (5)                "WHERE e.fooType = :fooType " +
>> (6)                  "AND e.name = :name"
>> (7)    )
>>
>> Case 1: if the given fooType is detached then if I create a named query
>> and
>> invoke getSingleResult() returns null.
>> Case 2: if I change the named query line (5) as following and the given
>> fooType is detached then it works:
>> (5)                "WHERE e.fooType.id = :fooTypeId " +
>> Case 3: if I "attach" the fooType prior to pass it to the query then it
>> works.
>>
>> Q1: Can someone please confirm is it true that any persistent entities
>> pass
>> as parameters to JPQL queries MUST be attached?
>>
>> Q2: What is the best way to "attach" a persistent entity without knowing
>> it's detached or not? (I invoke EntityManager.contains() and perform
>> EntityManager.find() is this recommended?)
>>
>> TIA,
>> Frank
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Persistent-entities-pass-as-params-to-JPQL-queries-MUST-be-attached--Query.getSingleResult%28%29-bug-or-expected-behavior--tf4471259.html#a12748830
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Persistent-entities-pass-as-params-to-JPQL-queries-MUST-be-attached--Query.getSingleResult%28%29-bug-or-expected-behavior--tf4471259.html#a12762081
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to