-->
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.  [ 4 posts ] 
Author Message
 Post subject: "select new" w/the object created by the query hav
PostPosted: Wed Dec 07, 2005 2:44 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Hibernate version: 3.1 rc2

Name and version of the database you are using: Sybase ASE 12

Here's my problem:

I'm trying to do a session.createQuery("select new myBean... but the hick is that one of the property of myBean is a set that will contain a mapped hibernate object (table2 objects).

Here's an example:

session.createQuery("select new myBean(table1.column1, table1.column2, table2) from table1 left join table2 where table1.id = :id)..setParameter( "id", new Long(11111)).list()

With "table2" I get the following error:

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [myBean] [select new ...

But without "table2" the query runs fine. Now, you need to know that I have two construtors in myBean, one with a SET and one without. I also have the join mapping (one-to-many) in table1 mapping.

I know I didn't give you everything you need to debug my problem but, I just want to know if this SHOULD be feasible or not. And, do I need JDK 5 for the Generics, to specify the type of SET the query will be returning (SET<table2>)?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 3:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The way that dynamic instantiation queries work is that you essentially end up with a "row" in the result for each row in the underlying JDBC result-set. For a query such as you are trying, the result-set rows will essentially be a product between your table1 and table2 such that for each of it's corresponding table2 rows, each table1 row will be duplicated.

Thus the constructor you really need is one that takes 3 params:
1) of type table1.column1
2) of type table1.column2
3) of type (whatever is mapped to table2)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 3:53 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
So Steve,

Is there a way to have one myBean object for each row in table1 and a SET populated with the rows from table2?

thx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 11:57 am 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Would an IDBAG work in this situation?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.