Announcement Announcement Module
Collapse
No announcement yet.
TransactionManager for Hibernate and save data fails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransactionManager for Hibernate and save data fails

    The problem is hibernate can make uuid after call save() method,but nothing save into db.

    code:
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName"><value>oracle.jdbc.OracleDr iver</value></property>
    <property name="url"><value>jdbc:oracle:thin:@localhost:1521 :orcl</value></property>
    <property name="username"><value>Acc4</value></property>
    <property name="password"><value>oracle</value></property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>domain/pojos/base/ContactInformation.hbm.xml</value>
    </list>
    </property>

    <property name="hibernateProperties">
    <props>
    <prop key="dialect.Dialect">net.sf.hibernate.dialect.Ora cle9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="jdbc.fetch_size">50</prop>
    <prop key="jdbc.batch_size">25</prop>
    <prop key="jdbc.use_scrollable_resultset">false</prop>
    <prop key="connection.useUnicode">true</prop>
    <prop key="connection.characterEncoding">UTF-8</prop>
    </props>
    </property>

    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- ========================= DAO Definitions: Hibernate implementation ========================= -->
    <bean id="contactInformationDAO" class="server.persistence.hibernate.ContactInforma tionDAOHibernateImpl">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- ========================= Business Object Definitions ======================== -->
    <bean id="baseTxProxy" lazy-init="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <bean id="employeeService" parent="baseTxProxy">
    <property name="target">
    <bean class="server.business.facade.impl.EmployeeService Impl">
    <property name="contactInformationDAO"><ref bean="contactInformationDAO"/></property>
    </bean>
    </property>
    </bean>
    code:




    public class EmployeeServiceImpl implements EmployeeService {

    /**
    *
    * @param o
    * @return
    */
    public String createContactInformation(ContactInformationView o) throws Exception {

    String result = null;
    try {
    ContactInformation pojo = (ContactInformation)BeanUtilsFactory.getBeanUtils( )
    .copyProperties(o);
    result = contactInformationDAO.createContactInformation(poj o);
    }
    catch (BeanConvertedException bce) {
    System.out.println(bce.getLocalizedMessage());
    }
    catch (Exception e) {
    System.out.println("exception:" + e.getLocalizedMessage());
    throw e;
    }
    return result;
    }

    public class ContactInformationDAOHibernateImpl extends HibernateDaoSupport
    implements ContactInformationDAO {

    /**
    *
    * @param o
    * @return
    */
    public String createContactInformation(ContactInformation o) throws DAOException {

    String result = null;

    try {
    result = (String)this.getHibernateTemplate().save(o);
    }
    catch (DataAccessException dae) {
    throw new DAOException(dae.getMessage());
    }
    System.out.println("uuid:" + result);
    return result;
    }

  • #2

    2004-09-17 11:58:55,495 DEBUG org.springframework.context.support.FileSystemXmlA pplicationContext - Publishing event in context [org.springframework.context.support.FileSystemXmlA pplicationContext;hashCode=10711912]: org.springframework.context.event.ContextRefreshed Event[source=org.springframework.context.support.FileSys temXmlApplicationContext: displayName=[org.springframework.context.support.FileSystemXmlA pplicationContext;hashCode=10711912]; startup date=[Fri Sep 17 11:58:52 CST 2004]; root of ApplicationContext hierarchy]
    2004-09-17 11:58:55,495 DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'employeeService'
    2004-09-17 11:58:55,495 DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Bean with name 'employeeService' is a factory bean
    2004-09-17 11:58:55,495 DEBUG org.springframework.transaction.interceptor.Transa ctionInterceptor - Getting transaction for method 'createContactInformation' in class [server.business.facade.EmployeeService]
    2004-09-17 11:58:55,505 INFO org.springframework.jdbc.datasource.DataSourceTran sactionObject - JDBC 3.0 Savepoint class is available
    2004-09-17 11:58:55,505 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Using transaction object [org.springframework.orm.hibernate.HibernateTransac tionObject@1926e90]
    2004-09-17 11:58:55,505 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Creating new transaction
    2004-09-17 11:58:55,505 DEBUG org.springframework.orm.hibernate.SessionFactoryUt ils - Opening Hibernate session
    2004-09-17 11:58:55,545 DEBUG net.sf.hibernate.impl.SessionImpl - opened session
    2004-09-17 11:58:55,545 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Opened new session [net.sf.hibernate.impl.SessionImpl@c68a98] for Hibernate transaction
    2004-09-17 11:58:55,545 DEBUG net.sf.hibernate.transaction.JDBCTransaction - begin
    2004-09-17 11:58:55,545 DEBUG net.sf.hibernate.transaction.JDBCTransaction - current autocommit status:true
    2004-09-17 11:58:55,545 DEBUG net.sf.hibernate.transaction.JDBCTransaction - disabling autocommit
    2004-09-17 11:58:55,545 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Exposing Hibernate transaction as JDBC transaction [org.apache.commons.dbcp.PoolableConnection@cc0e01]
    2004-09-17 11:58:55,575 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Bound value [org.springframework.jdbc.datasource.ConnectionHold er@ab7165] for key [org.apache.commons.dbcp.BasicDataSource@18aab40] to thread [main]
    2004-09-17 11:58:55,575 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Bound value [org.springframework.orm.hibernate.SessionHolder@15 70945] for key [net.sf.hibernate.impl.SessionFactoryImpl@1a1c42f] to thread [main]
    2004-09-17 11:58:55,575 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Initializing transaction synchronization
    2004-09-17 11:58:55,575 DEBUG server.business.facade.impl.EmployeeServiceImpl - createContactInformation(ContactInformationView) - start
    domain.view.base.ContactInformationView@e704be95
    2004-09-17 11:58:55,575 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Retrieved value [org.springframework.orm.hibernate.SessionHolder@15 70945] for key [net.sf.hibernate.impl.SessionFactoryImpl@1a1c42f] bound to thread [main]
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - generated identifier: 4028a725ff0a8ae200ff0a8ae6570001
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - saving [domain.pojos.base.ContactInformation#4028a725ff0a8 ae200ff0a8ae6570001]
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - calling onSave()
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - insertion vetoed by onSave()
    2004-09-17 11:58:55,575 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Retrieved value [org.springframework.orm.hibernate.SessionHolder@15 70945] for key [net.sf.hibernate.impl.SessionFactoryImpl@1a1c42f] bound to thread [main]
    id:4028a725ff0a8ae200ff0a8ae6570001
    2004-09-17 11:58:55,575 DEBUG server.business.facade.impl.EmployeeServiceImpl - createContactInformation(ContactInformationView) - end
    2004-09-17 11:58:55,575 DEBUG org.springframework.transaction.interceptor.Transa ctionInterceptor - Invoking commit for transaction on method 'createContactInformation' in class [server.business.facade.EmployeeService]
    2004-09-17 11:58:55,575 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Triggering beforeCommit synchronization
    2004-09-17 11:58:55,575 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Triggering beforeCompletion synchronization
    2004-09-17 11:58:55,575 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Initiating transaction commit
    2004-09-17 11:58:55,575 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Committing Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@c68a98]
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.transaction.JDBCTransaction - commit
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
    2004-09-17 11:58:55,575 DEBUG net.sf.hibernate.impl.SessionImpl - post flush
    2004-09-17 11:58:55,585 DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
    2004-09-17 11:58:55,585 DEBUG net.sf.hibernate.transaction.JDBCTransaction - re-enabling autocommit
    2004-09-17 11:58:55,585 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Triggering afterCompletion synchronization
    2004-09-17 11:58:55,585 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Clearing transaction synchronization
    2004-09-17 11:58:55,585 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Removed value [org.springframework.orm.hibernate.SessionHolder@15 70945] for key [net.sf.hibernate.impl.SessionFactoryImpl@1a1c42f] from thread [main]
    2004-09-17 11:58:55,585 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@ab7165] for key [org.apache.commons.dbcp.BasicDataSource@18aab40] from thread [main]
    2004-09-17 11:58:55,585 DEBUG org.springframework.orm.hibernate.HibernateTransac tionManager - Closing Hibernate session [net.sf.hibernate.impl.SessionImpl@c68a98] after transaction
    2004-09-17 11:58:55,585 DEBUG org.springframework.orm.hibernate.SessionFactoryUt ils - Closing Hibernate session
    2004-09-17 11:58:55,585 DEBUG net.sf.hibernate.impl.SessionImpl - closing session
    2004-09-17 11:58:55,585 DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
    2004-09-17 11:58:55,585 DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion

    Comment

    Working...
    X