On Thu, Nov 12, 2009 at 12:44 PM, Cil-Gamir <[email protected]>wrote:
>
> Hi Daryl
>
> I'm not closing the entity manager, where should I do this ?
>
Hard to say. What kind of app are you making? I have a webapp, so I have a
lazy creation mechanism for the em, at the completion of the HTTP request
thread, the EM is closed. So I have one EM per thread that is created and
closed in the lifetime of a single HTTP Request.
>
> I'm also not familiar with enhancing, my entity classes were declared as
> final, and JPA complained saying that it cannot do the enhancement for me
> if
> my classes are final.
>
> If I want to do the build time enhancement, where is a good place to start
> to figure out how.
>
Here's an Ant task that won't work with 1.2.1 if you reference enums:
<target name="EnhanceJPA">
<openjpac>
<classpath path="${classes}" />
<config propertiesFile="${src}/META-INF/persistence.xml"
connectionUserName="user"
connectionPassword="pw"
connectionURL="jdbc:postgresql://localhost/mydb"
connectionDriverName="org.postgresql.Driver" />
<fileset dir=".">
<include name="**/model/*.java" />
</fileset>
</openjpac>
</target>
Here's one that will:
<target name="EnhanceJPA">
<java classname="org.apache.openjpa.enhance.PCEnhancer">
<classpath>
<pathelement path="${classes}"/>
<pathelement path="${classpath}"/>
<fileset dir="/path/to/openjpa">
<include name="**/*.jar"/>
</fileset>
</classpath>
</java>
</target>
If I only save without persisting a new entity I can do that the whole day.
> but once I create a new entity the subsequent operation on any other entity
> or the newly saved one throws an optimistic locking exception
>
It's possible build time enhancement may take care of this, I don't know,
but you should be doing build-time anyway and depending on your app, closing
the em's.
--
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:[email protected]