Note that there are some explanatory texts on larger screens.

plurals
  1. POspring jpa hibernate writing to the DB fails - no transaction
    primarykey
    data
    text
    <p>i have the following problem. I use Spring and JPA (Hibernate) to persist Data in a Database. <br/> But i have an Error during saving the Data. My Database keeps empty after I create a new User. Here are the important files:</p> <pre><code>UserDao Interface: import java.util.List; public interface UserDao { public User findById(Integer id); public List&lt;User&gt; findAll(); public User findByEmail(String email); public void save(User user); } </code></pre> <p>UserDaoImpl:</p> <pre><code>@Repository public class UserDaoImpl implements UserDao { @PersistenceContext private EntityManager em; @Override public User findById(Integer id) { return em.find(User.class, id); } @SuppressWarnings("unchecked") @Override public List&lt;User&gt; findAll() { return (List&lt;User&gt;)em.createQuery("from User u").getResultList(); } @Override public User findByEmail(String email) { User user = null; try { user =  (User)em.createQuery("from User u where u.email = ?1").setParameter(1, email).getSingleResult(); } catch(NoResultException e){} return user; } @Override @Transactional public void save(User user) { em.persist(user); } } </code></pre> <p>Context.xml</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd" default-autowire="byName"&gt; &lt;context:component-scan base-package="de.bht.swp.lao.ocp" /&gt; &lt;context:annotation-config /&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="username" value="root" /&gt; &lt;property name="password" value="root" /&gt; &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt; &lt;property name="url" value="jdbc:mysql://localhost/ocp" /&gt; &lt;/bean&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceUnitName" value="ocpPU" /&gt; &lt;property name="dataSource" ref="dataSource"/&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="true" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="loadTimeWeaver" ref="loadTimeWeaver"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" &gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt; &lt;context:load-time-weaver weaver- class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt; &lt;/beans&gt; </code></pre> <p>persistence.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt; &lt;persistence-unit name="ocpPU"&gt; &lt;/persistence-unit&gt; </code></pre> <p></p> <p>When i create a new User i get the following Errorlog:</p> <pre><code>14:42:05,703 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - delaying identity-insert due to no transaction in progress 14:42:05,704 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] - Closing JPA EntityManager 14:42:05,707 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Rendering view  [org.springframework.web.servlet.view.RedirectView: unnamed; URL [/user/login.htm]] in   DispatcherServlet with name 'dispatcher' 14:42:05,708 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request </code></pre> <p>I think its a Trancation Error. I´v already spent so much time in other channels. What means "delaying identity-insert due to no transaction in progress"?</p> <p>thanks for the help beforehand greeting</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload