Announcement Announcement Module
Collapse
No announcement yet.
Hibernate and Spring not storing in DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate and Spring not storing in DB

    Hi,

    I am using hibernate with Spring to write to a mysql database. I can read from the database fine but when it comes to saving nothing is written to the DB.

    My application xml is as folows:

    <code>

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>com/medina/transferobjects/HajjVO.hbm.xml</value>
    <value>com/medina/transferobjects/ClientVO.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    <bean id="ClientDAO" class="com.medina.db.dao.hibernate.ClientDAOHibern ate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    bean id="clientTarget" class="com.medina.business.delegate.ClientDelegate Impl">
    <property name="clientDAO"><ref local="ClientDAO"/></property>
    </bean>


    <bean id="client" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/></property>
    <property name="target"><ref local="clientTarget"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED,ISOLATION_DEFAULT ,-DuplicateClientException</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    </code>

    I use the Hibernate Template and call the save and update method passing in my clientVO which is all populated when the method is called. When it returns from the method it process fine but when i check my db nothin has been saved.

    If I check my logs I see the following statement when it is trying to save:

    Hibernate: insert into client (title, first_name, mid_name, surname, gender) values (?, ?, ?, ?, ?).

    Also does anyone know how to get more hibernate logging. I have the show sql set to true in the context .xml

    Thanks in advance

  • #2
    Usually the problem with MySQL is not tolling back properly because people aren't using InnoDB.

    If Hibernate is issuing the insert statement and there is no rollback, then I'm not sure what the problem is. Can you write using straight JDBC?

    Comment


    • #3
      Do i need to set the transaction manager in my delegate which also sets the DAo object?

      Currently i only set the DAO object? could it be that I am not commiting the transaction. If I am not commiting does anyone know how to issue the commit?

      Comment


      • #4
        could it be that I am not commiting the transaction.
        Given the problem that seems likely.

        If I am not commiting does anyone know how to issue the commit?
        As long as you are using the client bean which is wrapped in a transactional proxy, it should issue a commit.

        Comment

        Working...
        X