-->
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: Foreign Key Column Validation not getting generated
PostPosted: Mon Aug 13, 2007 7:21 am 
Newbie

Joined: Mon Aug 13, 2007 7:06 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0
Mapping documents:
History.hbm.xml
Code:
<id name="id" type="java.lang.Long">
            <column name="ID" />
            <generator class="sequence" >
               <param name="sequence">HISTORY_ID_SEQ</param>
            </generator>
        </id>
        <many-to-one name="evn" class="Evn" cascade="none">
            <column name="fk_evn_id" not-null="true" />
        </many-to-one>

evn.hbm.xml
Code:
<list
         name="histories"
         inverse="true"
         cascade="all-delete-orphan"
         fetch="select"
         lazy="true">
         <key>
            <column
               name="fk_evn_Id"
               not-null="true" />
         </key>
         <index column="ID" type="java.lang.Long"></index>
         <one-to-many class="History" />
      </list>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: DB2 8.0
The generated SQL (show_sql=true):

Code:
select
       this_.ID     
   from
       EVN.EVN this_         
   where       
       and exists (
           select
               *               
           from
               EVN.HISTORY this0__               
           where
               this0__.INTERNALSTATE in (
                   50, 52, 55                   
               )               
             [red]  and this_.ID=this0__.fk_evn_id            [/red]
       )         

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?
As you see, there is a many-to-one mapping in evn and history tables. The sql part in red is not generated. This is hampering the performance of the job a lot. Please suggest how to include the sql in red part through Criteria API. Please note we are not using hql or any other way ONLY Critera API of hibernate.
Read this: http://hibernate.org/42.html

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 4:52 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Try something like this:
Code:
List internalStates = new ArrayList();
internalStates.add
....
DetachedCriteria dc = DetachedCriteria.forClass(Evn.class, "evn2")
.add(Restrictions.in("internalState", internalStates))
.add(Property.forName("evn.id").eqProperty("evn2.id"))
.setProjection(Projections.property("evn2.id"));

Criteria criteria = session.createCriteria(Evn.class, "evn")
.add(Subqueries.exists(dc));
List results = criteria.list();


Top
 Profile  
 
 Post subject: dc must be on History class??
PostPosted: Tue Aug 14, 2007 12:16 am 
Newbie

Joined: Mon Aug 13, 2007 7:06 am
Posts: 2
thanks for the response, I think we need to create Detached criteria dc on History table?? i do not see use of history table in ur soltn. please respond.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 2:11 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Yes, I just misread your sql. The detatched query should be on the history table but everything else is basically the same.


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.