Hi, I am facing a very common problem. I am not able to remove an entity from datatable. My entity class is:
My Dao class is:Code:public class ElectricDeviceEntity implements DeviceEntityInterface { @Id private int Id; private String name; @ManyToOne(optional=false,cascade=CascadeType.ALL,targetEntity=ProfileEntity.class) @JoinColumn(name="profile", referencedColumnName="id") private ProfileEntity profileEntity; private int device; @ManyToOne(optional=false,cascade=CascadeType.ALL,targetEntity=PortEntity.class) @JoinColumn(name="port", referencedColumnName="id") private PortEntity portEntity; // getters and setters }
Code:public class ElectricDeviceDao implements DeviceServiceInterface{ @PersistenceContext protected EntityManager entityManager; private ElectricDeviceEntity deviceEntity; private void InterfaceToEntity(DeviceEntityInterface deviceEntity) { this.deviceEntity = (ElectricDeviceEntity)deviceEntity; } public void deleteDevice(DeviceEntityInterface deviceEntityInterface) { InterfaceToEntity(deviceEntityInterface); deviceEntity = entityManager.merge(deviceEntity); entityManager.remove(this.deviceEntity); entityManager.flush(); } }
My service class is:
And my spring-config xml file is:Code:public class ElectricDeviceService implements DeviceServiceInterface{ @Autowired ElectricDeviceDao deviceDao; public void deleteDevice(DeviceEntityInterface deviceEntityInterface) { deviceDao.deleteDevice(deviceEntityInterface); } }
What can be the reason behind this error:Code:<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:component-scan base-package="com.infosys.ingreen.middleware.dao" /> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="IngreenMiddleware"/> </bean> <context:annotation-config/> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager"/> <property name="target"><ref bean="DeviceService"/></property> <property name="transactionAttributes"> <props> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="get*">PROPAGATION_REQUIRED</prop> <prop key="deleteDevice*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="DeviceService" class="com.infosys.ingreen.middleware.service.ElectricDeviceService"/> </beans>
Entity must be managed to call remove: com.infosys.ingreen.middleware.entity.ElectricDevi ceEntity@908881, try merging the detached and try the remove again.


Reply With Quote