Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: ORA-01002: fetch out of sequence error

  1. #11

    Default ORA-01002: fetch out of sequence

    I guess I am not very clear with the transactions concept yet with spring/hibernate. what are all the different procedures to set up transactions?

    I thought getHibernateTemplate() takes care of Transaction tx = s.beginTransaction(); and all that? Do I need any explicit code to do this?

    Need guidance.

    Thanks.

  2. #12
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    HibernateTemplate just handles Hibernate Session management, and will coordinate with an outer wrapping transaction, in terms of using any session that is already bound to the current thread and transaction, or depending on how it it set up, even creating a new session (which is what is happening for you).

    It does not do any creation or management of transactions itself. You need to set up transactions in a declarative or programmatic fashion. Please read the Spring documentation and look at the samples. There is extensive documentation on transaction handling in Spring, with and without Hibernate, and a decent amount of samples come with Spring which show the stuff in action.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #13

    Default session.flush()

    I have transaction defined as below in my application context file.
    <!-- Hibernate Transaction Manager -->
    <bean id="myTransactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory">
    <ref local="mySessionFactory"/>
    </property>
    </bean>

    <!-- Transaction Proxy Template -->
    <bean id="txProxyTemplate" lazy-init="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref local="myTransactionManager"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>
    <bean id="myEmailDAO" parent="txProxyTemplate">
    <property name="target">
    <ref local="myEmailTarget"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
    </props>
    </property>
    </bean>
    <bean id="myEmailTarget" class="com.xxx.hibernate.EmailDAOHibernateImpl" parent="myGenericDAO"/>

    My code:
    Session s = this.getSession();
    try {
    File attachment = new File("C:/temp/full_cream.gif");
    InputStream is = new FileInputStream(attachment);
    byte[] data = new byte[is.available()];
    is.read(data);
    is.close();

    byte[] test = {1};
    email.setEmailattachment(Hibernate.createBlob(test ));
    getHibernateTemplate().save(email);
    s.flush();
    getHibernateTemplate().refresh(email, LockMode.UPGRADE);

    OutputStream out = ((oracle.sql.BLOB) email.getEmailattachment()).getBinaryOutputStream( );
    out.write(data);
    out.close();

    If I dont have s.flush() in my code, I get an exception:
    Caused by: org.springframework.orm.hibernate.HibernateSystemE xception: this instance does not yet exist as a row in the database; nested exception is net.sf.hibernate.HibernateException: this instance does not yet exist as a row in the database.

    I thought spring handles flush() internally?? what am I missing??

    Thanks.

  4. #14
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    You wil get an automatic flush when the transaction ends. You of course also get a flush when the Session is closed, which in most usage scenarios will be the same lifetime as the transaction. Hibernate itself will decide to flush when you call certain Hibernate code, such as a query for example...

    You can either manually flush as you are doing, or you can also change the flush strategy in HibernateTemplate. You can for example set it to FLUSH_EAGER. However, that's going to force a flush after every operation, and is normally not recommended, as it will kill performance in most scenarios. The whole point is that you generally want to rely on Hibernate's session cache to speed things up. BTW, the need to flush and sync up when handling blobs is actually mentioned in the Hibernate docs or some of the Oracle specific stuff on the Hibernate wiki. I remember seeing a note about this. Finally, don't forget that Spring does have some LOB convenience classes, basically implementations of the LobHandler interface, such that you don't have to have Oracle specific code like you are using now...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 4
    Last Post: Nov 5th, 2004, 03:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •