[Teneo] Use objects in a query later on [message #985678] |
Thu, 15 November 2012 16:39 |
Thomas Kipar Messages: 7 Registered: January 2012 |
Junior Member |
|
|
Hi,
I am quite new to Hibernate and Teneo. What I try to do is the following: I have a query to get an entity. I save this object somewhere.
Later on, I would like to reuse this object in a different query (for a join). So I have...
ClassA a = query.list().get(0);
// somewhere else...
session.createQuery("FROM ClassB b WHERE b.a = :id"); // how to I use my existing a here?
To clarify: ClassB has a reference to ClassA. Am I right that I have to introduce explicit IDs in my model in order to solve this problem? I hoped the implicit IDs genereted by Teneo would be sufficient.
Thanks in advance.
Regards,
Thomas
[Updated on: Thu, 15 November 2012 17:21] Report message to a moderator
|
|
|
Re: [Teneo] Use objects in a query later on [message #985714 is a reply to message #985678] |
Thu, 15 November 2012 18:50 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Thomas,
As long as you are in the same session then you can re-use the same object, otherwise it is better to use the id of the
object for querying:
Query qry = session.createQuery("FROM B b WHERE b.a = :object");
qry.setParameter("object", object);
or
Query qry = session.createQuery("FROM B b WHERE b.a.id = :id");
qry.setParameter("id", object.getId());
There are several setParameter methods for different types of parameters.
gr. Martin
On 11/15/2012 05:39 PM, Thomas Kipar wrote:
> Hi,
>
> I am quite new to Hibernate and Teneo. What I try to do is the following: I have a query to get an entity. I save this
> object somewhere.
>
> Later on, I would like to reuse this object in a different query (for a join). So I have...
>
>
> ClassA a = query.list().get(0);
>
> // somewhere else...
> session.createQuery("FROM B b WHERE b.a = :id"); // how to I use my existing a here?
>
>
> Thanks in advance.
> Regards,
>
> Thomas
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
Powered by
FUDForum. Page generated in 0.03186 seconds