-->
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.  [ 3 posts ] 
Author Message
 Post subject: Binding problem when calling stored procedure
PostPosted: Mon Aug 28, 2006 11:56 am 
Newbie

Joined: Thu May 19, 2005 4:28 am
Posts: 6
Hello,

I am using hibernate 3.1.3 running from within JBoss 4.0.2, not as JMX bean but called from a stateless session bean that provides persistence services. The database is Oracle 9.2.0.4.0.

The problem I am having relates to binding and how hibernate is mapping that to jdbc calls.

Here is my hibernate.config.xml file:
Code:
<hibernate-configuration>

  <session-factory>
    <!-- Settings that apply to managed environments -->
    <property name="connection.datasource">java:/BlueSpaceDS</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
    <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <mapping resource="com/bluespace/core/persistence/config/hibernate/DeadLetter.hbm.xml"/>
  </session-factory>

</hibernate-configuration>


Here is the DeadLetter.hbm.xml file
Code:
<hibernate-mapping>

  <class name="com.bluespace.core.persistence.dlq.DeadLetterPersistentEntity" entity-name="DeadLetter" table="DLQ">
    <id name="jmsMessageId" column="jmsid">
      <generator class="native"/>
    </id>
    <property name="subscriberClassName" column="subscribertype"/>
    <property name="redeliveryCounter" column="redeliverycount"/>
    <property name="eventBytes" column="message"/>
  </class>

  <sql-query name="findByPeriod" callable="true">
    <return alias="dlq" entity-name="DeadLetter">
      <return-property name="jmsMessageId" column="jmsid"/>
      <return-property name="eventBytes" column="message"/>
      <return-property name="subscriberClassName" column="subscribertype"/>
      <return-property name="redeliveryCounter" column="redeliverycount"/>
    </return>
    { :result = call findByPeriod(:start, :end) }
  </sql-query>

</hibernate-mapping>


Here is my current code that binds the stored procedure:
Code:
         SessionFactory sessionFactory = HibernateSessionFactory.getInstance();
         Session session = sessionFactory.openSession(businessContext.getConnection(this.getDataSource()));
         Query finder = session.getNamedQuery(FIND_BY_PERIOD_NAME);
         finder.setInteger("result", 0);
         if (periodStart != null) {
            Calendar start = TimeKeeper.getCalendarInstance();
            start.setTimeInMillis(periodStart.getTime());
            finder.setCalendar(PERIOD_START_BINDING, start);
           }
         else {
            finder.setCalendar(PERIOD_START_BINDING, null);
           }
         if (periodEnd != null) {
            Calendar end = TimeKeeper.getCalendarInstance();
            end.setTimeInMillis(periodEnd.getTime());
            finder.setCalendar(PERIOD_END_BINDING, end);
           }
         else {
            finder.setCalendar(PERIOD_END_BINDING, null);
           }
         List deadLetters = finder.list();
         ...

   protected static final String PERIOD_START_BINDING = "start";
   protected static final String PERIOD_END_BINDING = "end";



The call "finder.setInteger("result", 0);" was inspired by http://forum.hibernate.org/viewtopic.php?t=958728&highlight=markerobject which helped me getting rid of the ClassCastException.

The problem that I continue to get is:
Caused by: java.sql.SQLException: Invalid column index
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:3703)
at oracle.jdbc.driver.OraclePreparedStatement.setNullInternal(OraclePreparedStatement.java:3594)
at oracle.jdbc.driver.OracleCallableStatement.setNull(OracleCallableStatement.java:4162)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setNull(WrappedPreparedStatement.java:351)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:55)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.loader.custom.CustomLoader.bindNamedParameters(CustomLoader.java:166)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1145)
at org.hibernate.loader.Loader.doQuery(Loader.java:373)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
at org.hibernate.loader.Loader.doList(Loader.java:1561)
... 65 more

When I use the oracle specific syntax:
Code:
BEGIN result := findByPeriod(:start, :end); END;


I get the strange error that not all named parameters are bound:
17:33:22,213 ERROR [LogInterceptor] RuntimeException in method: public abstract java.util.Collection com.bluespace.core.persistence.dlq.DeadLetterPersistenceManager.findByPeriod(com.bluespace.core.implementation.common.BusinessContext,java.sql.Timestamp,java.sql.Timestamp) throws javax.ejb.FinderException:
org.hibernate.QueryException: Not all named parameters have been set: [] [BEGIN :result := findByPeriod(:start, :end); END;]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:115)
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:138)
at com.bluespace.core.persistence.dlq.DeadLetterPersistenceManagerBean.findByPeriod(DeadLetterPersistenceManagerBean.java:180)

Can anybody help me out here please?

Rudi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 12:01 pm 
Newbie

Joined: Thu May 19, 2005 4:28 am
Posts: 6
Some progress:
My previous post said that I was using version 3.1.3 but apparently, version 4.0.2 of JBoss comes with hibernate 3.0.3. I was programming against version 3.1.3 but was actually using version 3.0.3

Now, I have switched to that version and also added the commons-collections-2.1.1.jar to the "jboss-hibernate.deployer" directory.

The situation has however got worse, now the Configuration does not load anymore with error:

Caused by: javax.ejb.EJBException: Unexpected Error
java.lang.NoClassDefFoundError: org/hibernate/cfg/SecondPass
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at com.bluespace.core.persistence.HibernateSessionFactory.getInstance(HibernateSessionFactory.java:30)

I have used the -verbose option when starting the VM but that does not give me any clue on an older version of a jar that is on the classpath.

Anyone that has a clue on how to fix this?

Many thanks,

Rudi.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 11:03 am 
Newbie

Joined: Thu May 19, 2005 4:28 am
Posts: 6
Fixed to problem by upgrading to jboss 4.0.4


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