-->
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: Hibernate 3 and custom insert SQL
PostPosted: Wed Feb 09, 2005 12:55 am 
Newbie

Joined: Mon Jan 24, 2005 11:48 pm
Posts: 5
Location: Newcastle, Australia
The documentation for custom inserts (http://www.hibernate.org/187.html) metions that you can use parameter names in the custom SQL. I am trying to insert a row into the database, but use the database server's current date for one of the columns.

When I try to do this, I get the exception below.

Are named parameters supported yet?

Code:
    <sql-insert>
      INSERT INTO payment_batch_group
        ( ID_payment_batch_group,
          ID_community,
          DT_created,
          ID_transaction_EDI,
          NO_order,
          ID_incoming_message,
          CD_file_format,
          CD_source)
      VALUES
        ( :paymentBatchGroupId,
          :communityId,
          SYSDATE,
          :paymentBatchGroupId,
          :groupOrderNumber, 
          :paymentBatchGroupId,
          :sourceCode,
          :fileFormatCode )
    </sql-insert>


Hibernate version: 3.0 beta 3

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

  <class name="com.qvalent.mts.entity.PaymentBatchGroup" table="Payment_Batch_Group"
      optimistic-lock="all" dynamic-update="true" lazy="false">

    <cache usage="read-write"/>

    <id name="paymentBatchGroupId" type="java.lang.Long" unsaved-value="null">
      <column name="ID_PAYMENT_BATCH_GROUP" not-null="true" sql-type="java.lang.Long"/>
      <generator class="com.qvalent.mts.entity.QvalentIdGen">
        <param name="sequence">Payment_Batch_Group_Seq</param>
        <param name="increment">100</param>
      </generator>
    </id>

    <property name="communityId" not-null="true" type="java.lang.Long">
      <column name="ID_Community" sql-type="timestamp"/>
    </property>
    <property name="createdDate" not-null="true" type="java.util.Date">
      <column name="DT_CREATED" sql-type="timestamp"/>
    </property>
    <property name="completedDate" not-null="false" type="java.util.Date">
      <column name="DT_COMPLETED" sql-type="timestamp"/>
    </property>
    <property name="transactionEdiId" not-null="true" type="java.lang.String">
      <column name="ID_TRANSACTION_EDI" sql-type="char(40)"/>
    </property>
    <property name="orderNumber" not-null="true" type="int">
      <column name="NO_ORDER" sql-type="int"/>
    </property>
    <property name="incomingMessageId" not-null="true" type="long">
      <column name="ID_INCOMING_MESSAGE" sql-type="long"/>
    </property>
    <property name="receiptDate" not-null="false" type="java.util.Date">
      <column name="DT_RECEIPT" sql-type="timestamp"/>
    </property>
    <property name="payloadXML" type="java.lang.String">
      <column name="XM_PAYLOAD" not-null="false" sql-type="char(4000)"/>
    </property>
    <property name="sourceCode" type="java.lang.String">
      <column name="CD_SOURCE" not-null="true" sql-type="char(20)"/>
    </property>
    <property name="fileFormatCode" type="java.lang.String">
      <column name="CD_FILE_FORMAT" not-null="false" sql-type="char(20)"/>
    </property>

    <set name="batches" inverse="true" cascade="all" lazy="true">
      <cache usage="read-write"/>
      <key column="ID_PAYMENT_BATCH_GROUP" />
      <one-to-many class="com.qvalent.mts.entity.PaymentBatch" />
    </set>

    <many-to-one name="community" cascade="all" column="ID_Community"
        class="com.qvalent.mts.entity.Community" fetch="select"
        insert="false" update="false"/>

    <sql-insert>
      INSERT INTO payment_batch_group
        ( ID_payment_batch_group,
          ID_community,
          DT_created,
          ID_transaction_EDI,
          NO_order,
          ID_incoming_message,
          CD_file_format,
          CD_source)
      VALUES
        ( :paymentBatchGroupId,
          :communityId,
          SYSDATE,
          :paymentBatchGroupId,
          :groupOrderNumber, 
          :paymentBatchGroupId,
          :sourceCode,
          :fileFormatCode )
    </sql-insert>

  </class>

</hibernate-mapping>


Name and version of the database you are using:
Oracle 10g

Exception stack trace:
Code:
org.springframework.jdbc.UncategorizedSQLException: (SessionSynchronization): encountered SQLException [Invalid column index]; nested exception is java.sql.SQLException: Invalid column index
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.setStringInternal(OraclePreparedStatement.java:4596)
   at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:4559)
   at com.metiom.core.datasource.PreparedStatementWrapper.setString(PreparedStatementWrapper.java:259)
   at com.metiom.core.datasource.PreparedStatementWrapper.setString(PreparedStatementWrapper.java:259)
   at org.hibernate.type.StringType.set(StringType.java:24)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
   at org.hibernate.persister.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1482)
   at org.hibernate.persister.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1462)
   at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1701)
   at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:2049)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:48)
   at org.hibernate.impl.ActionQueue.execute(ActionQueue.java:240)
   at org.hibernate.impl.ActionQueue.executeActions(ActionQueue.java:224)
   at org.hibernate.impl.ActionQueue.executeActions(ActionQueue.java:137)
   at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:265)
   at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:24)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:835)
   at org.springframework.orm.hibernate.SessionFactoryUtils$SpringSessionSynchronization.beforeCommit(SessionFactoryUtils.java:738)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:501)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:365)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.doCloseTransactionAfterThrowing(TransactionAspectSupport.java:278)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:60)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:619)
   at com.qvalent.mts.facade.BatchFacade$$EnhancerByCGLIB$$1ee73bf0.createBatchFile(<generated>)
   at com.qvalent.mts.servlet.batch.FileEditView.handleRequest(FileEditView.java:65)
   at com.metiom.core.servlet.UIServlet.baseService(UIServlet.java:318)
   at com.metiom.core.servlet.UIServlet.doPost(UIServlet.java:661)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 1:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, that page says: "maybe we should add support for :'syntax so it would be something like"

This is not implemented yet.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 1:10 am 
Newbie

Joined: Mon Jan 24, 2005 11:48 pm
Posts: 5
Location: Newcastle, Australia
Well obviously I'm in favor of it :)

Even so, I'd still have the problem of how to get the sysdate value from Oracle back into the object in the application, preferably without having to do an additional select.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 9:48 am 
Newbie

Joined: Fri Sep 15, 2006 10:29 am
Posts: 14
nclement wrote:
Well obviously I'm in favor of it :)

Even so, I'd still have the problem of how to get the sysdate value

Why don't you set SYSDATE as the DEFAULT value for this DT_created?


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.