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 89915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:47:29+00:00 2026-05-10T22:47:29+00:00

I’m trying to setup Spring using Hibernate and JPA, but when trying to persist

  • 0

I’m trying to setup Spring using Hibernate and JPA, but when trying to persist an object, nothing seems to be added to the database.

Am using the following:

<bean id='dataSource' class='org.apache.commons.dbcp.BasicDataSource'>     <property name='url' value='${jdbc.url}'/>     <property name='driverClassName' value='${jdbc.driverClassName}'/>     <property name='username' value='${jdbc.username}'/>     <property name='password' value='${jdbc.password}'/> </bean>  <bean id='entityManagerFactory' class='org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'>     <property name='dataSource' ref='dataSource' />     <property name='persistenceUnitName' value='BankingWeb' />     <property name='jpaVendorAdapter'>         <bean class='org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter'>             <property name='generateDdl' value='true' />             <property name='showSql' value='true' />             <property name='databasePlatform' value='${hibernate.dialect}' />         </bean>     </property> </bean>  <tx:annotation-driven/>  <bean id='transactionManager' class='org.springframework.orm.jpa.JpaTransactionManager'>     <property name='entityManagerFactory' ref='entityManagerFactory'/> </bean>  <bean class='org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor' />  <bean class='org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor'/>  <bean name='accountManager' class='ssel.banking.dao.jpa.AccountManager' /> <bean name='userManager' class='ssel.banking.dao.jpa.UserManager' /> 

And in AccountManager, I’m doing:

@Repository public class AccountManager implements IAccountManager {      @PersistenceContext private EntityManager em;      /* -- 8< -- Query methods omitted -- 8< -- */      public Account storeAccount(Account ac) {     ac = em.merge(ac);         em.persist(ac);         return ac;     } } 

Where ac comes from:

    Account ac = new Account();     ac.setId(mostRecent.getId()+1);     ac.setUser(user);     ac.setName(accName);     ac.setDate(new Date());     ac.setValue(0);     ac = accountManager.storeAccount(ac);     return ac; 

Is there anyone who can point out what I’m doing wrong? The persist call returns without throwing exceptions. If afterwards I do em.contains(ac), this returns true.

In case anyone needed, here’s how Account is defined:

@SuppressWarnings('serial') @Entity @NamedQueries({         @NamedQuery(name = 'Account.AllAccounts', query = 'SELECT a FROM Account a'),         @NamedQuery(name = 'Account.Accounts4User', query = 'SELECT a FROM Account a WHERE user=:user'),          @NamedQuery(name = 'Account.Account4Name', query = 'SELECT a FROM Account a WHERE name=:name'),         @NamedQuery(name = 'Account.MaxId', query = 'SELECT MAX(a.id) FROM Account a'),         @NamedQuery(name = 'Account.Account4Id', query = 'SELECT a FROM Account a WHERE id=:id'),     }) public class Account extends AbstractNamedDomain {     @Temporal(TemporalType.DATE)     @Column(name = 'xdate')     private Date date;      private double value;      @ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})     @JoinColumn(name='userid')     private User user;      public User getUser() {         return user;     }      public void setUser(User user) {         this.user = user;     }      @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)     @OrderBy('date')     private List<AccountActivity> accountActivity = new ArrayList<AccountActivity>();      public List<AccountActivity> getAccountActivity() {         return accountActivity;     }      public void setAccountActivity(List<AccountActivity> accountActivity) {         this.accountActivity = accountActivity;     }      public Date getDate() {         return date;     }      public void setDate(Date date) {         this.date = date;     }      public double getValue() {         return value;     }      public void setValue(double value) {         this.value = value;     }      public void addAccountActivity(AccountActivity activity) {         // Make sure ordering is maintained, JPA only does this on loading         int i = 0;         while (i < getAccountActivity().size()) {             if (getAccountActivity().get(i).getDate().compareTo(activity.getDate()) <= 0)                 break;             i++;         }         getAccountActivity().add(i, activity);     } }  @MappedSuperclass public abstract class AbstractNamedDomain extends AbstractDomain {      private String name;      public AbstractNamedDomain() {      }      public AbstractNamedDomain(String name) {          this.name = name;     }      public String getName() {         return name;     }      public void setName(String name) {         this.name = name;     } }  @MappedSuperclass public abstract class AbstractDomain implements Serializable {      @Id @GeneratedValue     private long id = NEW_ID;      public static long NEW_ID = -1;      public long getId() {         return id;     }      public void setId(long id) {         this.id = id;      }      public boolean isNew() {          return id==NEW_ID;     } } 
  • 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. 2026-05-10T22:47:30+00:00Added an answer on May 10, 2026 at 10:47 pm

    Thanks to eric and Juan Manuel’s answers, I was able to figure out that the transaction wasn’t committed.

    Adding @Transactional to the storeAccount method did the trick!

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

Sidebar

Ask A Question

Stats

  • Questions 246k
  • Answers 246k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You mean Type, using Activator.CreateInstance to create instances: public class… May 13, 2026 at 8:33 am
  • Editorial Team
    Editorial Team added an answer It is possible. One way to approach this is to… May 13, 2026 at 8:33 am
  • Editorial Team
    Editorial Team added an answer Facebook has a number of APIs, including ones which will… May 13, 2026 at 8:33 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.