簡體   English   中英

我如何告訴EclipseLink停止ServerSession連接查詢

[英]How do i tell EclipseLink to stop ServerSession Connection Queries

當查看我的堆棧跟蹤日志時,我注意到每當我使用實體管理器或EL(JPA 2.0)提供的方法em.find(), findAll() ...運行任何查詢時,所有相關的對象都會注入一個bean實體根據關系觸發n queries 我已經使用spring.instruments jar成功地啟用了與tomcat的編織,並且我非常確定正在發生編織,並且我的@ OneToOne,@ ManyToOne惰性設置已得到及時設置和編織。 問題可能是我如何查詢以及執行多個查詢的ServerSession連接。

堆棧跟蹤顯示如下:

[EL Fine]: sql: 2012-07-04 22:26:20.959--ServerSession(1528617164)--Connection(1657707912)--Thread(Thread[tomcat-http--9,5,main])--SELECT personID, TYPE, DATEADDED, FIRSTNAME, LASTNAME, MIDDLENAME, ACTIVE, BIRTHDAY, EMAILADDRESS, ETHNICITY, GENDER, HISPANIC, IMAGEPATH, MARITAL, NATIVELANGUAGE, PRIMARYTELEPHONE, RELIGIOUSAFFILIATION, SECONDARYTELEPHONE, version, addressID, schoolID, MAJOR, studentId FROM PERSON WHERE (personID = ?)
    bind => [101]
2012-07-04 22:26:20,963 [tomcat-http--9] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.Administrator': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Person.entityManager
2012-07-04 22:26:20,964 [tomcat-http--9] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
2012-07-04 22:26:20,964 [tomcat-http--9] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.Administrator': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Person.entityManager
2012-07-04 22:26:20,965 [tomcat-http--9] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
[EL Fine]: sql: 2012-07-04 22:26:20.966--ServerSession(1528617164)--Connection(264950364)--Thread(Thread[tomcat-http--9,5,main])--SELECT addressID, CITY, COUNTRY, STATE_US, STREETADDRESS, STREETADDRESS2, version, ZIPCODE FROM ADDRESS WHERE (addressID = ?)
    bind => [3]
2012-07-04 22:26:20,970 [tomcat-http--9] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.Address': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Address.entityManager
2012-07-04 22:26:20,971 [tomcat-http--9] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
[EL Fine]: sql: 2012-07-04 22:26:20.972--ServerSession(1528617164)--Connection(255059556)--Thread(Thread[tomcat-http--9,5,main])--SELECT personID, TYPE, DATEADDED, FIRSTNAME, LASTNAME, MIDDLENAME, ACTIVE, BIRTHDAY, EMAILADDRESS, ETHNICITY, GENDER, HISPANIC, IMAGEPATH, MARITAL, NATIVELANGUAGE, PRIMARYTELEPHONE, RELIGIOUSAFFILIATION, SECONDARYTELEPHONE, version, addressID, schoolID, MAJOR, studentId FROM PERSON WHERE (addressID = ?)
    bind => [3]
2012-07-04 22:26:20,975 [tomcat-http--9] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.Student': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Person.entityManager
2012-07-04 22:26:20,976 [tomcat-http--9] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
2012-07-04 22:26:20,976 [tomcat-http--9] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.Student': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Person.entityManager
2012-07-04 22:26:20,977 [tomcat-http--9] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
[EL Fine]: sql: 2012-07-04 22:26:20.98--ServerSession(1528617164)--Connection(2062869828)--Thread(Thread[tomcat-http--9,5,main])--SELECT schoolID, ACTIVE, ADMISSIONSEMAILADDRESS, ADMISSIONSPHONE, CODE, description, HELPGENERALEMAILADDRESS, NAME, PRIMARYPHONE, version, addressID FROM SCHOOL WHERE (schoolID = ?)
    bind => [3]
2012-07-04 22:26:20,982 [tomcat-http--9] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.School': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.School.entityManager
2012-07-04 22:26:20,982 [tomcat-http--9] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
[EL Fine]: sql: 2012-07-04 22:26:20.983--ServerSession(1528617164)--Connection(140234280)--Thread(Thread[tomcat-http--9,5,main])--SELECT id, ACTIVE, CODE, DESCRIPTION, NAME, version, SCHOOLDEPARTMENT_schoolID FROM DEPARTMENT WHERE (SCHOOLDEPARTMENT_schoolID = ?)
    bind => [3]
[EL Fine]: sql: 2012-07-04 22:26:20.986--ServerSession(1528617164)--Connection(1812702959)--Thread(Thread[tomcat-http--9,5,main])--SELECT personID, TYPE, DATEADDED, FIRSTNAME, LASTNAME, MIDDLENAME, ACTIVE, BIRTHDAY, EMAILADDRESS, ETHNICITY, GENDER, HISPANIC, IMAGEPATH, MARITAL, NATIVELANGUAGE, PRIMARYTELEPHONE, RELIGIOUSAFFILIATION, SECONDARYTELEPHONE, version, addressID, schoolID, MAJOR, studentId FROM PERSON WHERE (schoolID = ?)
    bind => [3]

在實體管理器對象上執行查詢后,如何忽略緩存並立即返回?

@RooJavaBean
@RooToString
@RooJpaActiveRecord(identifierColumn = "addressID")
public class Address {


    @Id
    @TableGenerator(name = "ADDRESS_TABLE_GEN", table = "ADDRESS_SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT", pkColumnValue = "ADDR_SEQ", allocationSize = 1, initialValue = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ADDRESS_TABLE_GEN")
    @Column(name = "addressID")
    private Long id;

    @BatchFetch(BatchFetchType.JOIN)
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "address", fetch = FetchType.EAGER)
    private Set<Person> persons = new HashSet<Person>();

申請人實體

public class Applicant extends Person {

    private String major;

    @BatchFetch(BatchFetchType.JOIN)
    @OneToMany(targetEntity = ApplicantSchool.class, cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REMOVE }, mappedBy = "applicant", fetch = FetchType.EAGER)
    private Set<ApplicantSchool> schools = new HashSet<ApplicantSchool>();

}

堆棧跟蹤; 還原特定的OneToOne映射

[TomcatInstrumentableClassLoader@747917a] error aspect 'org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect' woven into 'org.bixin.dugsi.domain.Registration_Roo_Jpa_ActiveRecord' must be defined to the weaver (placed on the aspectpath, or defined in an aop.xml file if using LTW).
[TomcatInstrumentableClassLoader@747917a] error aspect 'org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl' woven into 'org.bixin.dugsi.domain.Registration_Roo_Jpa_ActiveRecord' must be defined to the weaver (placed on the aspectpath, or defined in an aop.xml file if using LTW).
2012-07-06 17:08:34,910 ["http-bio-8080"-exec-1] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Found injected element on class [org.bixin.dugsi.domain.Registration]: PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Registration.entityManager
2012-07-06 17:08:34,910 ["http-bio-8080"-exec-1] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'org.bixin.dugsi.domain.Registration': PersistenceElement for transient javax.persistence.EntityManager org.bixin.dugsi.domain.Registration.entityManager
2012-07-06 17:08:34,911 ["http-bio-8080"-exec-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
2012-07-06 17:08:34,914 ["http-bio-8080"-exec-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0'
[EL Warning]: metadata: 2012-07-06 17:08:34.968--ServerSession(1433743869)--Thread(Thread["http-bio-8080"-exec-1,5,main])--Reverting the lazy setting on the OneToOne or ManyToOne attribute [person] for the entity class [class org.bixin.dugsi.domain.UserAccount] since weaving was not enabled or did not occur.

這就是EL所指的領域

   @OneToOne(targetEntity = Person.class, fetch = FetchType.LAZY) 
    @JoinColumn
    private Person person;

您已經在顯示的兩個關系中都指定了FetchType.EAGER,因此在構建源對象時必須始終提取它們。 如前所述,問題似乎是在“人”(或申請人)中讀取,從而導致獲取地址。 可能是“親自”的“地址” ManyToOne也被標記為渴望。 這將導致構建地址,並且由於您從Address-> Applicant獲得了1:M,因此該查詢必須轉到數據庫以確保它獲取了所有申請人。

在所有引用的急切獲取的實體上都發生同樣的現象,這就是為什么除非有必要(尤其是OneToMany和ManyToMany關系),否則將所有事物標記為急切的想法是一個壞主意。 我建議您將它們更改為惰性,並且僅在訪問該關系時才根據需要獲取它們,或者在查詢或查詢提示中使用訪存聯接來預取將需要的特定關系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM