Results 1 to 5 of 5

Thread: HibernateTemplate

  1. #1
    Join Date
    Sep 2004
    Location
    Oslo, Norway
    Posts
    17

    Default HibernateTemplate

    Hi
    I'm trying to use HibernateTemplate. When using .saveOrUpdate(Object) it works, but when using .save(Object) I get an SQLException, saying that the database is in read only mode.

    This is my TransactionProxyFactoryBean:

    <bean id="userStore" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref local="transactionManager"/>
    </property>
    <property name="target">
    <ref local="userStoreTarget"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    Anyone got any idea? I've probably just misunderstood something.
    Thanks
    - Kristian

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Kristian,
    Can your elaborate more, are your calling saveOrUpdate / save from the same method or from different methods? Could you also provide the log?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Sep 2004
    Location
    Oslo, Norway
    Posts
    17

    Default

    Hi
    Ok, this is the two methods I'm trying to use:

    public int addUser(
    String userName, String surName, String firstName,
    String telephoneNumber, String faxNumber, String cellNumber,
    String emailAddress, String userURL,
    UserRole userRole) {

    User user = new User();
    user.setUserName(userName);
    user.setSurName(surName);
    user.setFirstName(firstName);
    user.setTelephoneNumber(telephoneNumber);
    user.setFaxNumber(faxNumber);
    user.setCellNumber(cellNumber);
    user.setEmailAddress(emailAddress);
    user.setUserURL(userURL);

    return ((Integer)getHibernateTemplate().save(user)).intVa lue();
    }

    public void saveUser(User user)
    {
    getHibernateTemplate().saveOrUpdate(user);

    if (log.isDebugEnabled()) {
    log.debug("userID set to: " + user.getUserID());
    }
    }

    I'm trying to use theese two methods from the unit test class, from the same unit test, and I only try to call one of them. When I call saveUser(user) it works, but when calling addUser(........) I get this:

    http://folk.uio.no/krin/spring/log.txt

    It was so much output, so I figured putting it in a file would be best.

    Thanks
    - Kristian

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Kristian,

    The log result is absolutely correct:
    ...
    Getting transaction for method 'addUser' in class [no.uio.dhis.userstore.UserStore]
    ...
    Setting JDBC connection [org.hsqldb.jdbcConnection@1e7c5cb] read-only
    ...
    Method no.uio.dhis.userstore.UserStore.addUser is wrapped by a readonly Transaction as stated in your transaction demarcation
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    If you want your method to be wrapped with a read-write transaction, either change its name to "insertUser" or add a <prop key="add*">PROPAGATION_REQUIRED</prop> to transactionAttributes.

    As for method saveUser, It should fail too according to value of transactionAttributes. Could you show the log when using this method?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5
    Join Date
    Sep 2004
    Location
    Oslo, Norway
    Posts
    17

    Default

    Hi
    Thanks, I've misunderstood transactionAttributes. That part is now ok =) But when I now try to save one of my mapped objects I get an SQLException saying that it can't find the table, even though I see from the debug output that it gets created:

    This is the debug output/log:
    http://folk.uio.no/krin/spring/spring.txt

    Anyone got any idea about this?
    Thanks,
    Kristian

Similar Threads

  1. HibernateTemplate and transactions
    By Simon Brunning in forum Data
    Replies: 4
    Last Post: Mar 9th, 2009, 12:37 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. Inject HibernateTemplate into DAO
    By foamdino in forum Data
    Replies: 5
    Last Post: Jul 6th, 2005, 06:56 AM
  4. Replies: 0
    Last Post: May 19th, 2005, 04:10 PM
  5. Replies: 0
    Last Post: May 18th, 2005, 10:04 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
  •