hibernate - Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT -


this post in continuation of jpa how value database after persist

when execute following getting following exception, how can resolve this?

not allowed create transaction on shared entitymanager - use spring  transactions or ejb cmt 

daoimpl code

public void create(project project) {         entitymanager.persist(project);         entitymanager.gettransaction().commit();         project = entitymanager.find(project.class, project.getprojectid());         entitymanager.refresh(project);         system.out.println("id    -- " + project.getprojectid());             system.out.println("no -- " + project.getprojectno());     } 

applicationcontext.xml

<beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">      <bean id="datasource"         class="org.springframework.jdbc.datasource.drivermanagerdatasource">         <property name="username" value="scott" />         <property name="password" value="tiger" />         <property name="driverclassname" value="oracle.jdbc.driver.oracledriver" />         <property name="url" value="jdbc:oracle:thin:@myserver:1521:orcl" />     </bean>      <bean id="entitymanagerfactory"         class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="datasource" ref="datasource" />         <property name="packagestoscan" value="test.entity" />         <property name="jpavendoradapter">             <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter">                 <property name="showsql" value="true" />                 <property name="generateddl" value="false" />                 <property name="databaseplatform" value="org.hibernate.dialect.oracle10gdialect" />             </bean>         </property>     </bean>      <context:component-scan base-package="test.net" />      <tx:annotation-driven transaction-manager="transactionmanager"/>        <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager">         <property name="entitymanagerfactory" ref="entitymanagerfactory" />     </bean>                <context:annotation-config/>  </beans> 

i guess problem here although have defined bean transaction manager, haven't annotated create() method @transactional enables spring transactions.

also remove entitymanager.gettransaction().commit(); statement transaction management handled spring, if leave statement same error again.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -