Hayır EntityManager diyoruz 'devam' olamaz - güvenilir süreç devam, ben JUnit ile bir test yaptığınızdaHayır EntityManager - güvenilir süreç Şu anki işlem için kullanılabilir fiili işlemle
diyoruz 'devam' olamaz
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<!-- <bean id="notification" class="com.app.sqli.notification.NotificationTask" /> -->
<!-- <task:scheduled-tasks> -->
<!-- <task:scheduled ref="notification" method="notifier" cron="*/2 * * * * *"/> -->
<!-- </task:scheduled-tasks> -->
<context:component-scan base-package="com.app.sqli" />
<mvc:annotation-driven />
<bean id="entityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.app.sqli.entities" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/sqli" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryBean" />
</bean>
<tx:annotation-driven />
</beans>
: yöntem çalışır ve benim nesne yerleştirildiğinde görüyoruz, ama benim Kontrolör sayesinde yöntemini çağırdığınızda burada
çalışmıyor benim Projesi
benim Modeli Sınıf:
package com.app.sqli.models;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Collaborateur {
@Id
private int id;
private String nom;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
}
benim DAO Sınıf
package com.app.sqli.dao;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import com.app.sqli.models.Collaborateur;
@Repository
public class CollaborateurDao implements IcollaborateurDao{
@PersistenceContext
private EntityManager em;
@Override
public void addCollaborateur(Collaborateur c) {
em.persist(c);
}
}
Benim Hizmet Sınıfı
package com.app.sqli.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.app.sqli.dao.IcollaborateurDao;
import com.app.sqli.models.Collaborateur;
@Service
@Transactional
public class CollaborateurService implements IcollaborateurService{
@Autowired
private IcollaborateurDao cdao;
@Override
public void addCollaborateur(Collaborateur c) {
cdao.addCollaborateur(c);
}
}
Ve My Kontrolör
package com.app.sqli.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.app.sqli.models.Collaborateur;
import com.app.sqli.services.IcollaborateurService;
@org.springframework.stereotype.Controller
public class Controller {
@Autowired
private IcollaborateurService cserv;
@RequestMapping(value = "/index")
public String index(Model m) {
System.out.println("insertion ...");
Collaborateur c = new Collaborateur();
c.setId(11);
c.setNom("nom");
cserv.addCollaborateur(c);
return "index";
}
}
? İstisnaı bilmeden, aklıma gelen tek şey EM'nizde PersistenceContextType.Extended kullanıyor. @PersistenceContext (type = PersistenceContextType.EXTENDED) \t EntityManager em; – Mechkov
Aldığım Hata: org.springframework.web.util.NestedServletException: İstek işleme başarısız; iç içe istisna javax.persistence.TransactionRequiredException: Şu anki işlem için kullanılabilir fiili işlem ile hiçbir EntityManager - güvenilir işlemi PersistanceContextType.Extended ile denedin mi –
diyoruz 'devam' olamaz? Bilinmeyen bir varlık: Özetle, bu Şimdi ben bu hata mesajını var ... – Mechkov