In the Transactions lab (Lab11), if you want to
traverse the lazy relationship, add this code
to the servlet:


Collection<Award> awards = f.getAwards();
out.println("<table border='1'>");
for(Award a : awards)
{
    out.println("<tr>");
    out.println("<td>" + a.getDescription() + "</td>");
    out.println("<td>" + a.getMilesRequired() + "</td>");            
    out.println("</tr>");
}
out.println("</table>");


We get an exception, as expected - "Context is closed",
which means the Awards for the Flier were lazy, and the
persistence context is closed (similar to Hibernate LIE).

But if in Flier.java, we configure the relationship to
be EAGER, we get a runtime error:

<openjpa-2.4.0-nonfinal-1598334-r422266:1599166 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
FailedObject: SELECT f from Flier f WHERE f.flierID=:id [java.lang.String]
	at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:1031)
. . .

Apparently, the bug is that OpenJPA can only do eager fetching
if the entities are "enhanced". In fact, in the stack trace, there's
a warning about the un-enhanced entities.

One way to enhance them is to
write a build.xml Ant script in project's root:


<project name="jpa_enhance_builder" default="enhance">

	<property name="build.dir" location="build/classes"></property>
	<property name="openjpa.libs" location="C:\Users\jbarnum\java\apache-tomee-plus-1.7.1\lib" />
	
	<path id="enhance.cp">
	        <pathelement location="${basedir}${file.separator}${build.dir}"/>

	        <fileset dir="C:\Users\jbarnum\java\apache-tomee-plus-1.7.1\lib">
	            <include name="**/*.jar"/>
	        </fileset>
	</path>
	<property name="cp" refid="enhance.cp"/>
	
	<target name="openjpa.libs.check" unless="openjpa.libs">
		<fail message="Please set -Dopenjpa.libs in your builder configuration!"/>
	</target>
	<target name="build.dir.check" unless="build.dir">
		<fail message="Please set -Dbuild.dir in your builder configuration!"/>
	</target>
		
	<target name="enhance" depends="openjpa.libs.check, build.dir.check">
		<echo message="${cp}"/>
		<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
			<classpath refid="enhance.cp"/>
		</taskdef>
		<openjpac>
			<classpath refid="enhance.cp"/>
			<classpath location="${build.dir}" />
			<config propertiesFile = "${build.dir}/META-INF/persistence.xml"/>
		</openjpac>
	</target>
</project>


Then stop the server, clean it, run the build script and then publish. Then it should work when
you run the AwardServlet again.