openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] OpenJPA > Entity Enhancement
Date Wed, 11 Aug 2010 14:00:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/5/_/styles/combined.css?spaceKey=openjpa&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/openjpa/Entity+Enhancement">Entity
Enhancement</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~drwoods">Donald
Woods</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        added link to user docs<br />
    </div>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The JPA spec requires some type of
monitoring of Entity objects, but the spec does not define how to implement this monitoring.
Some JPA providers auto-generate new subclasses or proxy objects that front the user&#39;s
Entity objects at runtime, while others use byte-code weaving technologies to enhance the
actual Entity class objects at build time.  OpenJPA supports both methods, but strongly suggests
only using the *build time* enhancement. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">For
complete details on entity enhancement, please checkout the section in the latest [User&#39;s
Guide on Enhancement|http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_enhance].
 The following sections will only cover the high-level concepts and the ways to use the enhancer
in different build and runtime setups. <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Build Time Enhancement <br>
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        

<h1><a name="EntityEnhancement-WhatisEnhancementAnyway%3F"></a>What is Enhancement
Anyway?</h1>

<p>The JPA spec requires some type of monitoring of Entity objects, but the spec does
not define how to implement this monitoring. Some JPA providers auto-generate new subclasses
or proxy objects that front the user's Entity objects at runtime, while others use byte-code
weaving technologies to enhance the actual Entity class objects at build time.  OpenJPA supports
both methods, but strongly suggests only using the <b>build time</b> enhancement.</p>

<p>For complete details on entity enhancement, please checkout the section in the latest
<a href="http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_enhance"
class="external-link" rel="nofollow">User's Guide on Enhancement</a>.  The following
sections will only cover the high-level concepts and the ways to use the enhancer in different
build and runtime setups.</p>


<h2><a name="EntityEnhancement-BuildTimeEnhancement"></a>Build Time Enhancement</h2>

<p>Build time enhancement is the recommended method to use with OpenJPA, as it it the
fastest and most reliable method.  Please follow the links below based on your development
environment:</p>

<ul>
	<li><a href="/confluence/display/openjpa/Enhancement+with+ANT" title="Enhancement
with ANT">Enhancement with ANT</a></li>
	<li><a href="/confluence/display/openjpa/Enhancement+with+Maven" title="Enhancement
with Maven">Enhancement with Maven</a></li>
	<li><a href="/confluence/display/openjpa/Enhancement+with+Eclipse" title="Enhancement
with Eclipse">Enhancement with Eclipse</a></li>
</ul>



<h2><a name="EntityEnhancement-RuntimeEnhancement"></a>Runtime Enhancement</h2>

<p>When running in a Java SE environment or in a non-Java EE 5 compliant container,
OpenJPA defaults to using runtime subclassing enhancement. The subclassing enhancement support
was added originally as a convenience to new developers to reduce the amount of work to get
a 'HelloWorld-ish' OpenJPA application working out of the box. It was never meant to run in
production. So you're probably thinking that this sounds great! OpenJPA handles enhancement
automatically for me and I can stop reading this post. Wrong! Subclassing has two major drawbacks.
First off, it isn't nearly as fast as byte-code enhancement and the second drawback is that
there are some documented functional problems when using the subclassing support. The moral
of the story is, don't use this method of enhancement.</p>

<p>If you really want to use runtime enhancement, the following <a href="/confluence/display/openjpa/Runtime+Enhancement"
title="Runtime Enhancement">Runtime Enhancement</a> page describes how to use the
<em>-javaagent</em> setting in ANT and Eclipse projects.</p>

<p>Additional information regarding the subclassing enhancement can be found in the
<a href="http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_enhance"
class="external-link" rel="nofollow">OpenJPA docs</a>.</p>

<h2><a name="EntityEnhancement-DynamicEnhancement"></a>Dynamic Enhancement</h2>

<p><a href="https://issues.apache.org/jira/browse/OPENJPA-952" class="external-link"
rel="nofollow">OPENJPA-952</a> added the capability to have OpenJPA attempt to dynamically
load the javaagent enhancer. If you see the following message, OpenJPA loaded the enhancer
dynamically.</p>
<blockquote><p>[java] 1453  jpa_app  INFO   [main] openjpa.Runtime - OpenJPA dynamically
loaded the class enhancer. Any classes that were not enhanced at build time will be enhanced
when the are loaded by the JVM.</p></blockquote>

<p>This method of enhancement is intended for first time users or developers as it has
a number of caveats.</p>
<ul>
	<li>It only works on Sun 1.6SDK, not the JRE and IBM JDK (SR8+).</li>
	<li>If any unenhanced Entities are loaded by the JVM before an EntityManagerFactory
is created, this method of enhancement will not work. If this condition is encountered, you
will see the following warning:
<blockquote><p>[java] 1047  jpa_app  WARN   [main] openjpa.Enhance - Unenhanced
classes were detected even though the enhancer has ran. Ensure that the EntityManagerFactory
is created prior to creating any Entities.</p></blockquote></li>
</ul>


<p>If your application uses some other method of enhancement, this support can be disabled
by setting the following property in your persistence.xml.</p>
<blockquote><p>&lt;property name="openjpa.DynamicEnhancementAgent" value="false"/&gt;</p></blockquote>

<h2><a name="EntityEnhancement-AuthorAttribution"></a>Author Attribution</h2>

<p>The content for this page and sub-pages was adapted from content created by OpenJPA
contributor Rick Curtis from the following <a href="http://webspherepersistence.blogspot.com/"
class="external-link" rel="nofollow">WebSphere and Java Persistence</a> blog entries:<br/>
<a href="http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html" class="external-link"
rel="nofollow">http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html</a><br/>
<a href="http://webspherepersistence.blogspot.com/2009/04/openjpa-enhancement-eclipse-builder.html"
class="external-link" rel="nofollow">http://webspherepersistence.blogspot.com/2009/04/openjpa-enhancement-eclipse-builder.html</a></p>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/openjpa/Entity+Enhancement">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27090&revisedVersion=10&originalVersion=9">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/openjpa/Entity+Enhancement?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message