em.clear()로 모든 객체를 분리했지만 연결된 객체가 분리 된 것을 볼 수 없습니까? 연결된 객체를 분리하는 방법은 무엇입니까?JPA에서 연결된 객체를 분리하는 방법
I have a method as :
public CustomerSurvey getSurveyByRequest(long requestNo)
throws WorkServiceException {
logger.debug("Inside getSurveyByRequest : " + requestNo);
EntityManager em = entityManagerFactory.createEntityManager();
Query query = em.createNamedQuery("customerSurvey.findByRequest")
.setParameter("srNo", requestNo);
List<CustomerSurvey> surveys = query.getResultList();
**em.clear();**
em.close();
return surveys.get(0);
}
CustomerSurvey.java :
@Entity
@Table(name = "CUSTOMER_SURVEY", uniqueConstraints = { @UniqueConstraint(columnNames
= "SERVEYID") })
@SequenceGenerator(name="CUSTOMER_SURVEY_SEQUENCE",
sequenceName="CUSTOMER_SURVEY_SEQUENCE", initialValue=1, allocationSize=100)
@NamedQueries({
@NamedQuery(name="customerSurvey.findByRequest",
query="SELECT survey FROM CustomerSurvey survey " +
"WHERE survey.serviceRequest.srNo = :srNo")
})
public class CustomerSurvey implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="CUSTOMER_SURVEY_SEQUENCE")
@Column(name = "SURVEYID", nullable = false)
private String surveyId;
@ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.DETACH)
@JoinColumn(name="CUSTNO", referencedColumnName="CustNO")
private Customer customer;
@Column(name="AVGRATINGS")
private int avgRatings;
@Column(name="COMMENTS")
private String comments;
@Column(name="SENTON")
private Date sentOn;
@Column(name="RESPONDEDON")
private Date respondedOn;
@OneToMany(fetch=FetchType.LAZY,mappedBy="customerSurvey")
private Set<SurveyResponse> responses;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="SRNO")
private ServiceRequest serviceRequest;
내 테스트 클래스 :
CustomerSurvey survey = workService.getSurveyByRequest(request.getSrNo());
System.out.println("survey = " + survey);
System.out.println("survey id = " + survey.getSurveyId());
System.out.println("survey customer = " + survey.getCustomer());
오류 메시지 :
조사 = com.ge.dsp.iwork.entity.CustomerSurvey @ 36b88ea5 survey id = 131 스레드의 예외 "SpringOsgiExtenderThread -134 "org.springframework.beans.factory.BeanCreationException : URL [번들 : //178.124 : 0/META-INF/spring/module- context.xml]에 정의 된 이름 'testCloseRequest'로 bean 생성 오류 : init 호출 메서드가 실패했습니다. 중첩 예외가 javax.jdo.JDODetachedFieldAccessException : 필드 "고객"에 액세스하려했지만 객체를 분리 할 때이 필드가 분리되지 않았습니다. 이 필드에 액세스하지 않거나 개체를 분리 할 때 분리하십시오. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:519)에서 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1455) 에서 org.springframework에서 .BeansFactory $ 1.getObject (AbstractBeanFactory.java:294) at support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:291)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons에서 org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:193) (DefaultListableBeanFactory.java:609) org.springframework에서 에서 515,. org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext에서 org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access $ 1600 context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:918) (AbstractDelegatedExecutionApplicationContext.java:69) $ 4.run (AbstractDelegatedExecutionApplicationContext.java:355) at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL (PrivilegedUtils.java:85)org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor $ CompleteRefreshTask.run에서 org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh (AbstractDelegatedExecutionApplicationContext.java:320) 에서 0 (DependencyWaiterApplicationContextExecutor.java:132) at java.lang.Thread.run (Thread.java:662) 발생 원인 : javax.jdo.JDODetachedFieldAccessException : 방금 필드 "고객"에 액세스하려고했으나이 필드는 객체를 분리 할 때 분리되지 않았습니다. 이 필드에 액세스하지 말거나 개체를 분리 할 때 분리하십시오. at com.ge.dsp.iwork.entity.CustomerSurvey.jdoGetcustomer (CustomerSurvey.java) at com.ge.dsp.iwork.entity.CustomerSurvey.getCustomer (CustomerSurvey.java:89) at com.ge.dsp. iwork.test.WorkServiceTest.testCloseRequest (WorkServiceTest.java:181) at sun.reflect.NativeMethodAccessorImpl.java.lang.reflect.Method.invoke에서 sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) 에서 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) 에서 invoke0 (기본 방법) (방법 된 .java : 597)에 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod (AbstractAutowireCapableBeanFactory.java:1581) 에서 (AbstractAutowireCapableBeanFactory.java:1522) (AbstractAutowireCapableBeanFactory.java:1452) ... 14 더 많은
어디에서이 문서를 찾을 수 있습니까? –