Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DetatchedCriteria without on clause

 
Tommaso Agostinacchio
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!

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.
 
Tommaso Agostinacchio
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really I think it is due to the kay in the hibernate.hbm.xml. But is it possible to avoid or change the autogenerated on condition?

<class name="enitities.T_gwr_proposals" table="t_gwr_proposals">
<id name="proposalsId" type="java.lang.Integer">
<column name="ID" />
<generator class="increment" />
<!-- <param name="sequence">t_gwr_proposals_ID_SEQ</param>
</generator> -->
</id>
<set name="T_gwr_proposal_ratings" table="t_gwr_proposal_ratings"
lazy="true" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>

<one-to-many class="enitities.T_gwr_proposal_ratings" />
</set>
<property name="sndg" type="java.lang.Integer">
<column name="SNDG" not-null="true" />
</property>
<property name="ndg" type="java.lang.Integer">
<column name="NDG" not-null="true" />
</property>
<property name="t_gwr_partner_id" type="java.lang.Integer">
<column name="T_GWR_PARTNER_ID" length="54" not-null="true" />
</property>
</class>

Thanks a lot,

Tommaso
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic