-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem de ClassCastException with Character and String
PostPosted: Fri Aug 20, 2010 5:49 pm 
Regular
Regular

Joined: Wed Jan 28, 2009 8:31 pm
Posts: 54
Hi everyone , I m have a ClassCastException
this is my dao
Code:
public List<TprchsSaleTrans> findTprchsSaleTrans()
{
  List<Object> l = null;
  TprchsSaleTrans prchsSaleTrans = null;
  List<TprchsSaleTrans> listReturn = new ArrayList<TprchsSaleTrans>();
try {
l = this.getHibernateTemplate().[B]findByNamedQuery[/B("tprchsSaleTransQuery");
for (Object list : l)
{
    Object[] element = (Object[]) list;
    prchsSaleTrans = new TprchsSaleTrans();
    prchsSaleTrans.setTprchssaletransID((Integer) element[0]);
      //In bd BranchCd = 199 et hibernate give me only the first char
     [B]prchsSaleTrans.setBranchCd((String) element[1]);[/B]
listReturn.add(prchsSaleTrans);......
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      return listReturn;
   }
}

my mapping
Code:
<hibernate-mapping>
    <class name="TprchsSaleTrans" table="tprchs_sale_trans">
         <id name="tprchssaletransID" type="java.lang.Integer">
            <column name="tprchs_sale_trans_ID" />
            <generator class="identity" />
        </id>
            <property name="accountCd" type="string">
                <column name="account_cd" length="5" />
            </property>
            [B]<property name="branchCd" type="string">
                <column name="branch_cd" length="3" />
            </property>[/B]....
</class>
    [B] <sql-query name="tprchsSaleTransQuery">
      <![CDATA[select tprchs_sale_trans_ID,branch_cd,account_cd,type_account_cd,chck_brch_acct_nbr, transaction_dt,currency_cd,sum(case when debit_credit_cd = 'C' then tran_total_amt * -1 else tran_total_amt  end) as net FROM tprchs_sale_trans where  CONVERT(varchar(20), transaction_dt,105 )   = CONVERT(varchar(20),GETDATE(),105) or (CONVERT(varchar(20), processing_dt,105 )   = CONVERT(varchar(20),GETDATE()-1,105) and  transaction_dt  <=   GETDATE() ) GROUP by branch_cd,account_cd,type_account_cd,chck_brch_acct_nbr,transaction_dt,currency_cd,tprchs_sale_trans_ID]]>
   </sql-query>[/B]
</hibernate-mapping>

my pojo
Code:
private String branchCd;


I dont know why hibernate give me
a result char for my string branchCd
the ddl for
branch_cd is char size= 3
Can anyone can tell me please what happening thank in advance


Top
 Profile  
 
 Post subject: Re: Problem de ClassCastException with Character and String
PostPosted: Fri Aug 20, 2010 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you have written a native SQL query, so Hibernate is executing it literally and not mapping it to easy-to-use objects, in this case the types are defined by your database & driver, as it would happen when using JDBC directly.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Problem de ClassCastException with Character and String
PostPosted: Mon Aug 23, 2010 3:12 pm 
Regular
Regular

Joined: Wed Jan 28, 2009 8:31 pm
Posts: 54
ok it look like , I will have to do some hsq. But I don t Know if hsq support the case and convert. Now a I have a compilation error
Code:
public List<TprchsSaleTrans> findTprchsSaleTrans()
   {
      List<Object> l = null;
      TprchsSaleTrans prchsSaleTrans = null;
      List<TprchsSaleTrans> listReturn = new ArrayList<TprchsSaleTrans>();
      try {         
         String varHql = "select sale.tprchssaletransID,sale.branchCd,sale.accountCd,sale.typeAccountCd,sale.chckBrchAcctNbr, sale.transactionDt,sale.currencyCd ,sum(case when sale.debitCreditCd ='C' then sale.tranTotalAmt * -1 else sale.tranTotalAmt  end) as net FROM TprchsSaleTrans sale GROUP by sale.branchCd,sale.accountCd,sale.typeAccountCd,sale.chckBrchAcctNbr,sale.transactionDt,sale.currencyCd,sale.tprchssaletransID";
         l = getSession().createQuery(varHql).list();
         for (Object list : l) {
            Object[] element = (Object[]) list;

            prchsSaleTrans = new TprchsSaleTrans();
            prchsSaleTrans.setTprchssaletransID((Integer) element[0]);

            prchsSaleTrans.setBranchCd((String) element[1]);
            prchsSaleTrans.setAccountCd((String) element[2]);
            prchsSaleTrans.setTypeAccountCd((Character) element[3]);
            prchsSaleTrans.setChckBrchAcctNbr((Character) element[4]);
            prchsSaleTrans.setTransactionDt((Date) element[5]);
            prchsSaleTrans.setCurrencyCd((String) element[6]);
            prchsSaleTrans.setNet((BigDecimal) element[7]);
            listReturn.add(prchsSaleTrans);

         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      return listReturn;
   }

Quote:
java.lang.NoClassDefFoundError: antlr/ANTLRException
at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:35)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:74)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at TprchsSaleTransDao.findTprchsSaleTrans(TprchsSaleTransDao.java:28)
at TprchsSaleTransDaoTest.testFindTprchsSaleTrans(TprchsSaleTransDaoTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
or in the hql editor
Quote:
org.hibernate.hql.ask.QuerySyntaxException:*near line 1 colunm 198[select sale.tprchssaletransID,sale.branchCd,sale.accountCd,sale.typeAccountCd,sale.chckBrchAcctNbr, sale.transactionDt,sale.currencyCd ,sum(case when sale.debitCreditCd =]

It seem there a problem with sale.debitCreditCd ='C'
or with the multiplication sale.tranTotalAmt * (-1)

can somebody help me please


Top
 Profile  
 
 Post subject: Re: Problem de ClassCastException with Character and String
PostPosted: Mon Aug 23, 2010 4:48 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
java.lang.NoClassDefFoundError: antlr/ANTLRException

means you're missing a class, likely you're missing antlr.jar or having a wrong version.
Please post the version of libraries you're using

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Problem de ClassCastException with Character and String
PostPosted: Tue Aug 24, 2010 1:13 pm 
Regular
Regular

Joined: Wed Jan 28, 2009 8:31 pm
Posts: 54
thank now I put the antlr jar.
and this is what happen now in the hql editor
Code:
select sale.tprchssaletransID,sale.branchCd,sale.accountCd,sale.typeAccountCd,sale.chckBrchAcctNbr, sale.transactionDt,sale.currencyCd ,sum(case when sale.debitCreditCd ='C' then (sale.tranTotalAmt * -1) else sale.tranTotalAmt  end) as net FROM TprchsSaleTrans sale GROUP by sale.branchCd,sale.accountCd,sale.typeAccountCd,sale.chckBrchAcctNbr,sale.transactionDt,sale.currencyCd,sale.tprchssaletransID
and the console give me

Quote:
org.hibernate.hql.ask.QuerySyntaxException:*near line 1 colunm 198[select sale.tprchssaletransID,sale.branchCd,sale.accountCd,sale.typeAccountCd,sale.chckBrchAcctNbr, sale.transactionDt,sale.currencyCd ,sum(case when sale.debitCreditCd =]
a mapping probleme .
It impossible.

Now what happen , if I want steal stand why
sql qyery for
Code:
<sql-query name="tprchsSaleTransQuery">
      <![CDATA[select tprchs_sale_trans_ID,branch_cd,account_cd,type_account_cd,chck_brch_acct_nbr, transaction_dt,currency_cd,sum(case when debit_credit_cd = 'C' then tran_total_amt * -1 else tran_total_amt  end) as net FROM tprchs_sale_trans where  CONVERT(varchar(20), transaction_dt,105 )   = CONVERT(varchar(20),GETDATE(),105) or (CONVERT(varchar(20), processing_dt,105 )   = CONVERT(varchar(20),GETDATE()-1,105) and  transaction_dt  <=   GETDATE() ) GROUP by branch_cd,account_cd,type_account_cd,chck_brch_acct_nbr,transaction_dt,currency_cd,tprchs_sale_trans_ID]]>
   </sql-query>
and what to have
branch_cd char size= 3
more then just a caractere?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.