-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Retrieve set problem
PostPosted: Sat May 01, 2004 7:33 am 
Newbie

Joined: Wed Mar 24, 2004 6:18 am
Posts: 15
Hi everyone. I have two tables, say table1 and table2, with a one to many relation. Accordingly, the table1 java object has a Set of table2 elements, and the table2 object has one table1 object.

When I get a complete table1 object, with a query like this:

Code:
from table1 where id=:id


the object is retrieved with no problems, and it has its Set of table2 objects filled correctly.

But if I try to get just the Set of table2 objects this way:

Code:
select elements(table2) from table1 where id=:id


then the query doesn't complete because it seems to enter an infinite loop.

Isn't that query the way to get just the Set of table2 objects?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 8:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
select elements(p.childs) from parent p where p.id=:id


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 4:11 am 
Newbie

Joined: Wed Mar 24, 2004 6:18 am
Posts: 15
delpouve wrote:
select elements(p.childs) from parent p where p.id=:id


Hi delpouve, thanks for your answer. I didn't have the code in front of me when I wrote the message so I wrote some sort of pseudocode, but in fact I was already using an alias for the table. I was making another mistake on my query which apparently caused the infinite loop.

But now I have another problem.

If I write:

Code:
from parent p where p.id=:id


Then I get a "parent" object with a Set of "child" objects inside. But if I write:

Code:
select p.id, elements(p.childs) from parent p where p.id=:id


Then I get many "parent" objects (one for each child) with one "child" object, and I want a single "parent" object with a Set of "child" objects.

If I don't call the "elements()" function, I get an error executing the query, because Hibernate expects this function or "indices()".

I've also tried this:

Code:
select p.id, elements(p.childs) from parent p join fetch p.childs where p.id=:id


with no luck.

How can I do what I want?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 5:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
How can I do what I want?


Its a bit unclear what you want.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:12 am 
Newbie

Joined: Wed Mar 24, 2004 6:18 am
Posts: 15
gavin wrote:
Its a bit unclear what you want.


OK, I will try to explain it as clear as I can.

If I execute this:

Code:
from parent p where p.id=:id


The resulting list has one object of type "parent" which has a Set of N objects of type "child". N is the number of childs of the given parent.

If I execute this:

Code:
select p.id, elements(p.childs) from parent p where p.id=:id


The resulting list has N arrays of 2 objects, the first one being the ID and the second one an object of type "child".

What I would want is that the resulting list had just one array of 2 objects, the first one being the ID and the second one a Set of N objects of type "child".

Sorry but I can't explain it better.

I would get the whole object using the first query, but the "parent" table is too big and I don't need all its fields.

The last thing I've tried is declaring a constructor like this:

Code:
public parent(Long id, Set childs)


and with a query like this:

Code:
select new parent(p.id, elements(p.childs)) from parent p where p.id=:id


but Hibernate tells me that "parent" class doesn't have the requested constructor.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not possible.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:44 am 
Newbie

Joined: Wed Mar 24, 2004 6:18 am
Posts: 15
gavin wrote:
This is not possible.


Thanks a lot, gavin, I thought it could be.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.