Results 1 to 5 of 5
  1. #1
    TommymmoT75 is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Question DetatchedCriteria without on clause

    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_propos al_id", "Table1.proposalsId"));
    return c.list();

    Can anyone help me, please?

    Thank you very much,

    Tommaso A.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,048
    Rep Power
    6

    Default Re: DetatchedCriteria without on clause

    If you want to invoke SQL then invoke SQL. Using Hibernate ORM mappings you want to obtain a RESULT, not a specific query.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    TommymmoT75 is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Re: DetatchedCriteria without on clause

    Thanks for the answer. Anyone can give me a little more help?

  4. #4
    TommymmoT75 is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Re: DetatchedCriteria without on clause

    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

  5. #5
    TommymmoT75 is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Re: DetatchedCriteria without on clause

    What mean for result?

Similar Threads

  1. where clause in hibernate
    By me.anchit in forum JDBC
    Replies: 0
    Last Post: 09-29-2011, 08:01 PM
  2. Need help to write where clause
    By SAR in forum New To Java
    Replies: 4
    Last Post: 07-01-2010, 09:00 AM
  3. finally clause
    By arefeh in forum New To Java
    Replies: 6
    Last Post: 01-30-2010, 09:11 PM
  4. Using escape sequence with like clause (%)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:57 AM
  5. Using escape sequence with like clause (_)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •