-->
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: Select count problem
PostPosted: Fri Nov 04, 2005 5:46 pm 
Newbie

Joined: Thu Jun 09, 2005 9:53 am
Posts: 6
Hibernate version: 3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
// Within an interceptor
private boolean initialAuditExists(String tableName, String rowIdAsString) {
   boolean rv = false;

   String countQuery = "select count(d) from myproduct.audit.transaction.TransactionAuditInterceptor d "
              + "where d.tablename=:tableName and d.rowidasstring=:rowIdAsString";
   String[] paramNames = new String[]{"tableName", "rowIdAsString"};
   Object[] paramValues = new Object[]{tableName, rowIdAsString};

   Session tempSession = null;
   try {
      tempSession = HibernateAdapter.openSession(session.connection());
      Integer count = (Integer) HibernateAdapter.getScalarQuery(tempSession, countQuery, paramNames, paramValues);
      if (null != count && 0 < count.intValue()) {
         rv = true;
      }
   } catch (HibernateException e) {
      logger.error(e);
   } finally {
      if (null != tempSession ) {
         tempSession.close();
      }
   }
   return rv;
}


Full stack trace of any exception that occurs:
2005-11-04 15:42:33,955 [main] WARN org.hibernate.hql.QuerySplitter - no persistent classes found for query class: select count(d) from myproduct.audit.transaction.TransactionAuditInterceptor d where d.tablename=:tableName and d.rowidasstring=:rowIdAsString

Name and version of the database you are using:
SQL Server 2000 SP4

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

In the example above, the operation is always returning false because the count is null. I've verified that there is data that matches the query. Is there a typo in my query?


Top
 Profile  
 
 Post subject: Re: Select count problem
PostPosted: Fri Nov 04, 2005 5:51 pm 
Newbie

Joined: Thu Jun 09, 2005 9:53 am
Posts: 6
Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="myproduct.audit.transaction.TransactionAudit"
        table="myproduct_transactionaudit"
    >

        <id
            name="id"
            column="id"
            type="long"
            unsaved-value="-1"
        >
            <generator class="native">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-TransactionAudit.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <many-to-one
            name="user"
            class="myproduct.orderentry.data.User"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
        >
            <column
                name="user_id"
                index="ix_user"
            />
        </many-to-one>

            <property
                name="workstationId"
                type="java.lang.String"
                    update="true"
                    insert="true"
        >
            <column
                name="workstationid"
                length="254"
            />
        </property>

            <property
                name="timeStamp"
                type="java.util.Date"
                    update="true"
                    insert="true"
            column="timeStamp"
        />

            <property
                name="tableName"
                type="java.lang.String"
                    update="true"
                    insert="true"
        >
            <column
                name="tablename"
                length="254"
            />
        </property>

            <property
                name="rowIdAsString"
                type="java.lang.String"
                    update="true"
                    insert="true"
        >
            <column
                name="rowidasstring"
                length="254"
            />
        </property>

            <property
                name="rowIdAsLong"
                type="java.lang.Long"
                    update="true"
                    insert="true"
        >
            <column
                name="rowidaslong"
                length="254"
            />
        </property>

            <property
                name="columnName"
                type="java.lang.String"
                    update="true"
                    insert="true"
        >
            <column
                name="columnname"
                length="254"
            />
        </property>

            <property
                name="value"
                type="java.lang.String"
                    update="true"
                    insert="true"
            column="value"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-TransactionAudit.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Select count problem (resolved)
PostPosted: Fri Nov 04, 2005 5:55 pm 
Newbie

Joined: Thu Jun 09, 2005 9:53 am
Posts: 6
Duh ... the persistent class name in the query is wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:21 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
try
Code:
String countQuery = "select count(d.rowidasstring) from myproduct.audit.transaction.TransactionAuditInterceptor d "
              + "where d.tablename=:tableName and d.rowidasstring=:rowIdAsString";


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.