I have set a lazy collection up, as the rest payload over Jersey is too much, and I don't actually need this particular collection populated all the time.
I set the collection to Lazy, expecting it to not be present in my rest response, but it is still being populated.
Is Jersey somehow triggering the population of the collection somehow?
@OneToMany(mappedBy="gpt", orphanRemoval = false, cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE }, fetch = FetchType.LAZY)
@XmlElement
@XmlInverseReference(mappedBy = "gpt")
protected List<PrOpalProject> projects;
I am using spring repositories, not sure that's relevant (?) and EclipseLink
EDIT:
My persistence.xml file is using static weaving and my pom.xml is as below:
persistence.xml
<properties>
<property name="eclipselink.target-database" value="Oracle"/>
<property name="eclipselink.ddl-generation" value="none"/>
<property name="eclipselink.weaving" value="static"/>
</properties>
<!-- This plugin ensures the EclipseLink static weaving -->
<plugins>
<plugin>
<artifactId>eclipselink-staticweave-maven-plugin</artifactId>
<groupId>au.com.alderaan</groupId>
<version>1.0.4</version>
<executions>
<execution>
<goals>
<goal>weave</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<logLevel>ALL</logLevel>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipselink.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only.
It has no influence on the Maven build itself. -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>au.com.alderaan</groupId>
<artifactId>eclipselink-staticweave-maven-plugin</artifactId>
<versionRange>[1.0.4,)</versionRange>
<goals>
<goal>weave</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
UPDATE 2:
I have put some start up code in my app, and have enabled EclipseLink Logging at FINE level.
I have one lazy collection (projects) and one Eager collection (products)
public void init() {
List<PrGPT> gpts = gptService.getAllGPTs();
for (PrGPT prGPT : gpts) {
System.out.println(prGPT.getProjects().size());
System.out.println(prGPT.getProducts().size());
}
In my console, only the call the getProjects.size() causes a SQL trigger...implying that with Jersey out of the equation, lazy loading is working. See console output below:
[EL Fine]: sql: 2014-10-13 16:48:16.896--ServerSession(2099597535)--Connection(347358184)--Thread(Thread[localhost-startStop-1,5,main])--SELECT ID, APPROVED_PRIORITY, DISEASE, DISEASE_AREA, DPOM_BPOM_PHASE, IMED, MOLECULE_OR_TYPE_OF_PRODUCT, PLANNING_STATUS, PROGRAM_CATEGORY_DESC, PROGRAM_TYPE_DESC, PROJECT_CODE, PROJECT_NM, STATE, PROJECT_TYPE, THERAPY_AREA, GPT FROM PR_OPAL_PROJECT WHERE (GPT = ?)
bind => [17000]
0
0
[EL Fine]: sql: 2014-10-13 16:48:22.817--ServerSession(2099597535)--Connection(2007184558)--Thread(Thread[localhost-startStop-1,5,main])--SELECT ID, APPROVED_PRIORITY, DISEASE, DISEASE_AREA, DPOM_BPOM_PHASE, IMED, MOLECULE_OR_TYPE_OF_PRODUCT, PLANNING_STATUS, PROGRAM_CATEGORY_DESC, PROGRAM_TYPE_DESC, PROJECT_CODE, PROJECT_NM, STATE, PROJECT_TYPE, THERAPY_AREA, GPT FROM PR_OPAL_PROJECT WHERE (GPT = ?)
bind => [17050]
0
0
[EL Fine]: sql: 2014-10-13 16:48:25.06--ServerSession(2099597535)--Connection(202457351)--Thread(Thread[localhost-startStop-1,5,main])--SELECT ID, APPROVED_PRIORITY, DISEASE, DISEASE_AREA, DPOM_BPOM_PHASE, IMED, MOLECULE_OR_TYPE_OF_PRODUCT, PLANNING_STATUS, PROGRAM_CATEGORY_DESC, PROGRAM_TYPE_DESC, PROJECT_CODE, PROJECT_NM, STATE, PROJECT_TYPE, THERAPY_AREA, GPT FROM PR_OPAL_PROJECT WHERE (GPT = ?)
bind => [9500]
1
0
The call to "getProducts.size()" doesn't trigger SQL.
So I can only assume this is a Jersey "thing"...
Even though, reading around the internet, I have set my XMLAccessorType to be "@XmlAccessorType(XmlAccessType.FIELD)". This apparently should not cause the lazy loaded collection to be brought over.
Regards
i