Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Use objects in a query later on
[Teneo] Use objects in a query later on [message #985678] Thu, 15 November 2012 16:39 Go to next message
Thomas Kipar is currently offline Thomas KiparFriend
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 Go to previous message
Martin Taal is currently offline Martin TaalFriend
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
Previous Topic:[EuGENia] Issue with the generated editor
Next Topic:Texo - implementing an interface
Goto Forum:
  


Current Time: Thu Apr 25 20:43:37 GMT 2024

Powered by FUDForum. Page generated in 0.02697 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top