Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:54:06+00:00 2026-06-12T12:54:06+00:00

I am trying to implement a simple DAO using hibernate 4 and Spring 3.

  • 0

I am trying to implement a simple DAO using hibernate 4 and Spring 3.

When I try to save or delete a row in the db the transaction is not persisted. I have included some code to show how the saving in the db doesnt work:

I have a junit test which simply tries to save a StockEntityDTO in the db.

@RunWith(SpringJUnit4ClassRunner.class)
public class StocksDAOImplTest extends
    AbstractTransactionalJUnit4SpringContextTests {

@Autowired
protected StocksDAO stockDao;


@Test
public void shouldInsertIntoDatabase() {
    BigDecimal price = new BigDecimal(653.50);
    StockEntityDTO savedStock = new StockEntityDTO("GOOG", price, "google");
    stockDao.create(savedStock);
    StockEntityDTO retrievedStock = stockDao.getById(savedStock.getId());
    assertEquals(savedStock, retrievedStock);
}

The test passes but the expected row (1, “GOOG”, 653.50, “google”) is not persisted in the db.

The DAO looks like this:

@Transactional
public abstract class AbstractHibernateDAO<T extends Serializable> {

private Class<T> clazz;


@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;


public void setClazz(final Class<T> clazzToSet) {
    this.clazz = clazzToSet;
}


public void create(final T entity) {
    Session session = this.getCurrentSession();
    session.save(entity);

}

Application Context:

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
    <property name="username" value="gtp" />
    <property name="password" value="gtp" />
</bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.ubs.gtp.data.domain" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext
            </prop>
        </props>
    </property>
</bean>

Hope someone can help. As is probably evident from my code, I am very new to spring.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:54:07+00:00Added an answer on June 12, 2026 at 12:54 pm

    AbstractTransactionalJUnit4SpringContextTests rolls back after the test. Try setting a breakpoint at the last line and then inspecting the database. You can use the Rollback annotation if you don’t want this default behaviour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
Using Hibernate 3.6.8.Final and Spring 3.0.5.RELEASE , I'm trying to add some Common DAO
I'm trying to implement a simple DAO. I have a Dao: @Repository(iUserDao) @Transactional(readOnly =
I've been trying to implement simple low level keyhook using JNI and all went
I am trying to implement a simple login servlet but it's not working properly.
Trying to implement simple error handling without adding buku try / except statements to
im trying to implement simple secured client server communiction using WCF. when im launching
I am trying to implement simple chat application using flex. In it all my
I'm trying to implement Simple chat using Servlet 3.0 and Comet pattern based on
I'm trying to implement a simple login system in Rails, but when I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.