DetatchedCriteria without on clause

I'm relatively new to Hibernate. I have to use the 3.2 version and i need to use DetachedCriteria and obtain the following query:

select this_.ID as ID0_1_, this_.SNDG as SNDG0_1_
, this_.NDG as NDG0_1_, this_.T_GWR_PARTNER_ID as T4_0_1_
, table2x1_.ID as ID1_0_, table2x1_.T_GWR_PROPOSAL_ID as T2_1_0_
, table2x1_.GROUP_SNDG as GROUP3_1_0_, table2x1_.GROUP_NAME as GROUP4_1_0_
from t_gwr_proposals this_ 
inner join 
t_gwr_proposal_ratings table2x1_ 
where table2x1_.T_GWR_PROPOSAL_ID=this_.ID

but I obtain the follwing

select this_.ID as ID0_1_, this_.SNDG as SNDG0_1_
, this_.NDG as NDG0_1_, this_.T_GWR_PARTNER_ID as T4_0_1_
, table2x1_.ID as ID1_0_, table2x1_.T_GWR_PROPOSAL_ID as T2_1_0_
, table2x1_.GROUP_SNDG as GROUP3_1_0_, table2x1_.GROUP_NAME as GROUP4_1_0_ 
from t_gwr_proposals this_ 
inner join t_gwr_proposal_ratings table2x1_ 
** on this_.ID=table2x1_.ID ** 
where table2x1_.T_GWR_PROPOSAL_ID=this_.ID

using this code:

Criteria c = session.createCriteria(T_gwr_proposals.class, "Table1");
c.createAlias("Table1.T_gwr_proposal_ratings", "Table2"); // inner join by default
c.add(Restrictions.eqProperty("Table2.t_gwr_proposal_id", "Table1.proposalsId"));
return c.list();

Can anyone help me, please?

Thank you very much,

Tommaso A.

Answers


Criteria doesn't work with tables, but with entities and their association. You can only join two entities via the associations that exist between them. And only one root entity can exist in a criteria query. So, you won't be able to create such a query in Criteria (HQL should do fine, though) unless an association exists between the entities that uses table2x1_.T_GWR_PROPOSAL_ID=this_.ID as its mapping.


Need Your Help

Best Web2.0 framework for Java?

java jsf wicket web2.0 spring-roo

this question is quite related to the one asked here, however, I am not interested in the best web framework, but in the best web2.0 framework for Java. First, here is what I want to achieve:

Getting “Unknown iOS Detected” everytime in Xcode Organizer when I connect my device iOS 4.2.1

iphone xcode ios4

I get the same screen everytime I connect my device to the Mac. This thing started happening after I installed iOS 4.2.1 on my iPhone. It takes several minutes each time to recognize the device...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.