-->
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: Using "where in"
PostPosted: Wed Aug 02, 2006 4:24 pm 
Newbie

Joined: Tue Jul 25, 2006 6:39 pm
Posts: 16
Location: Dallas, TX
Trying to use this HQL: DELETE TransactionLogTemp WHERE TransactionLogTemp.Transactionid in (%1)

replace %1 with a list of id's comma separated

Hibernate version: 3.1.3

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
    <class name="com.travelbahn.xgwStats.hib.TransactionLogTemp" table="TransactionLog_temp" catalog="AmexPerf">
        <id name="transactionid" type="integer">
            <column name="TRANSACTIONID" />
            <generator class="assigned" />
        </id>
        <property name="sessionid" type="integer">
            <column name="SESSIONID" />
        </property>
        <property name="clientid" type="string">
            <column name="CLIENTID" length="100" />
        </property>
        <property name="parentTrxid" type="integer">
            <column name="PARENT_TRXID" />
        </property>
        <property name="trxState" type="string">
            <column name="TRX_STATE" length="100" />
        </property>
        <property name="trxStart" type="timestamp">
            <column name="TRX_START" length="19" not-null="true" />
        </property>
        <property name="totalTrxTime" type="integer">
            <column name="TOTAL_TRX_TIME" />
        </property>
        <property name="trxName" type="string">
            <column name="TRX_NAME" length="100" />
        </property>
        <property name="userid" type="integer">
            <column name="USERID" />
        </property>
        <property name="clientIp" type="string">
            <column name="CLIENT_IP" length="20" />
        </property>
        <property name="servicingHost" type="string">
            <column name="SERVICING_HOST" length="100" />
        </property>
        <property name="travelerid" type="integer">
            <column name="TRAVELERID" />
        </property>
        <property name="loggingApp" type="string">
            <column name="LoggingApp" length="100" />
        </property>
        <property name="metricName1" type="string">
            <column name="METRIC_NAME1" length="100" />
        </property>
        <property name="metricValue1" type="string">
            <column name="METRIC_VALUE1" length="100" />
        </property>
        <property name="metricName2" type="string">
            <column name="METRIC_NAME2" length="100" />
        </property>
        <property name="metricValue2" type="string">
            <column name="METRIC_VALUE2" length="100" />
        </property>
        <property name="metricName3" type="string">
            <column name="METRIC_NAME3" length="100" />
        </property>
        <property name="metricValue3" type="string">
            <column name="METRIC_VALUE3" length="100" />
        </property>
        <property name="metricName4" type="string">
            <column name="METRIC_NAME4" length="100" />
        </property>
        <property name="metricValue4" type="string">
            <column name="METRIC_VALUE4" length="100" />
        </property>
        <property name="metricName5" type="string">
            <column name="METRIC_NAME5" length="100" />
        </property>
        <property name="metricValue5" type="string">
            <column name="METRIC_VALUE5" length="100" />
        </property>
        <property name="metricName6" type="string">
            <column name="METRIC_NAME6" length="100" />
        </property>
        <property name="metricValue6" type="string">
            <column name="METRIC_VALUE6" length="100" />
        </property>
        <property name="metricName7" type="string">
            <column name="METRIC_NAME7" length="100" />
        </property>
        <property name="metricValue7" type="string">
            <column name="METRIC_VALUE7" length="100" />
        </property>
        <property name="metricName8" type="string">
            <column name="METRIC_NAME8" length="100" />
        </property>
        <property name="metricValue8" type="string">
            <column name="METRIC_VALUE8" length="100" />
        </property>
        <property name="metricName9" type="string">
            <column name="METRIC_NAME9" length="100" />
        </property>
        <property name="metricValue9" type="string">
            <column name="METRIC_VALUE9" length="100" />
        </property>
        <property name="metricName10" type="string">
            <column name="METRIC_NAME10" length="100" />
        </property>
        <property name="metricValue10" type="string">
            <column name="METRIC_VALUE10" length="100" />
        </property>
        <property name="metricName11" type="string">
            <column name="METRIC_NAME11" length="100" />
        </property>
        <property name="metricValue11" type="string">
            <column name="METRIC_VALUE11" length="100" />
        </property>
        <property name="metricName12" type="string">
            <column name="METRIC_NAME12" length="100" />
        </property>
        <property name="metricValue12" type="string">
            <column name="METRIC_VALUE12" length="100" />
        </property>
        <property name="metricName13" type="string">
            <column name="METRIC_NAME13" length="100" />
        </property>
        <property name="metricValue13" type="string">
            <column name="METRIC_VALUE13" length="100" />
        </property>
        <property name="metricName14" type="string">
            <column name="METRIC_NAME14" length="100" />
        </property>
        <property name="metricValue14" type="string">
            <column name="METRIC_VALUE14" length="100" />
        </property>
        <property name="metricName15" type="string">
            <column name="METRIC_NAME15" length="100" />
        </property>
        <property name="metricValue15" type="string">
            <column name="METRIC_VALUE15" length="100" />
        </property>
        <property name="metricName16" type="string">
            <column name="Metric_Name16" length="100" />
        </property>
        <property name="metricValue16" type="string">
            <column name="Metric_Value16" length="100" />
        </property>
        <property name="metricName17" type="string">
            <column name="Metric_Name17" length="100" />
        </property>
        <property name="metricValue17" type="string">
            <column name="Metric_Value17" length="100" />
        </property>
        <property name="metricName18" type="string">
            <column name="Metric_Name18" length="100" />
        </property>
        <property name="metricValue18" type="string">
            <column name="Metric_Value18" length="100" />
        </property>
        <property name="metricName19" type="string">
            <column name="Metric_Name19" length="100" />
        </property>
        <property name="metricValue19" type="string">
            <column name="Metric_Value19" length="100" />
        </property>
        <property name="metricName20" type="string">
            <column name="Metric_Name20" length="100" />
        </property>
        <property name="metricValue20" type="string">
            <column name="Metric_Value20" length="100" />
        </property>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
      StatelessSession session = sessionFactory.openStatelessSession();
      Transaction tx = session.beginTransaction();
      
      Query q = session.createQuery(stmt);
      int ret = q.executeUpdate();
      
      tx.commit();
      
      session.close();


Full stack trace of any exception that occurs:
Code:
Exception in thread "main" java.lang.NullPointerException
   at org.hibernate.hql.ast.tree.IdentNode.resolveAsNakedComponentPropertyRefLHS(IdentNode.java:195)
   at org.hibernate.hql.ast.tree.IdentNode.resolve(IdentNode.java:85)
   at org.hibernate.hql.ast.tree.DotNode.resolveFirstChild(DotNode.java:139)
   at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:462)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4316)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1211)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4032)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3832)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1758)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:425)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:245)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at com.travelbahn.xgwStats.hib.HibBaseProcess.doUpdate(HibBaseProcess.java:32)
   at com.travelbahn.xgwStats.AnalyzePerfHib.deleteDupes(AnalyzePerfHib.java:197)
   at com.travelbahn.xgwStats.AnalyzePerfHib.clearDupes(AnalyzePerfHib.java:175)
   at com.travelbahn.xgwStats.AnalyzePerfHib.process(AnalyzePerfHib.java:93)
   at com.travelbahn.xgwStats.XGWStatsProcess.process(XGWStatsProcess.java:51)
   at com.travelbahn.xgwStats.XGWStatsProcess.main(XGWStatsProcess.java:179)


Name and version of the database you are using:
MySQL 5


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 5:29 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Try the following code

Code:
String hql = "DELETE TransactionLogTemp tlt WHERE tlt.Transactionid in ( ":mydeleteids" ) ";
Query q = session.createQuery( hql );
q.setParameterList( "mydeleteids", new Object[]{ "ID1", "ID2","ID3" } );
int count = q.executeUpdate();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 22, 2006 9:25 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
I'm using 3.2.0 GA

Code:
   <query name="search.files">
      <![CDATA[
         from File file where file.id in ( :ids )
      ]]>
   </query>


Code:
      query.setParameterList( "ids", new Object[]{ new Integer(1), new Integer(2)});


(File.id is the primary key and is of Integer type)

Fails with...

Code:
org.hibernate.TypeMismatchException: named parameter [ids] not of expected type; expected = class java.lang.Integer; but was =[Ljava.lang.Object;
   at org.hibernate.loader.hql.QueryLoader.bindNamedParameters(QueryLoader.java:520)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2144)
   at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2060)
   at org.hibernate.loader.Loader.list(Loader.java:2020)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)



What in the world I'm missing here ? I'm debugging away but if any of you find an answer please drop a line or two.

My best,
Q


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 22, 2006 10:02 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
It's my bad... Please disregard!

I passed a wrong type to setParameterList()


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.