openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Corey Klaasmeyer (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-72) PersistenceProviderImpl.createContainerEntityManagerFactory() should not add a ClassTransformerImpl to PersistenceUnitInfo if <exclude-unlisted-classes>
Date Tue, 31 Oct 2006 17:55:17 GMT
    [ http://issues.apache.org/jira/browse/OPENJPA-72?page=comments#action_12445975 ] 
            
Corey Klaasmeyer commented on OPENJPA-72:
-----------------------------------------

You can choose NOT to specify a LoadTimeWeaver in Spring by changing this bean markup:

<beans>
 ...
 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="someDataSource"/>
  <property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
  </property>
 </bean>
</beans>

to this markup:

<beans>
 ...
 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="someDataSource"/>
 </bean>
</beans>

However, this currently will fail with an IllegalStateException because of this parameter
check in SpringPersistenceUnitInfo:

...
	/**
	 * Method called by PersistenceProvider to add instrumentation to
	 * the current environment.
	 */
	public void addTransformer(ClassTransformer classTransformer) {
		if (this.loadTimeWeaver == null) {
			throw new IllegalStateException("Cannot apply class transformer without LoadTimeWeaver
specified");
		}
		this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer));
	}

...

In my opinion, your second option is preferrable -- "do some work (if possible) before registering
the ClassTransformer to see if all the classes are already persistence-capable". This could
be done by checking the parameter that you refer to here -- "I thought that there was an OpenJPA
configuration setting that could be used to turn off this behavior, but I don't see it" --
if it exists. Or, you can rely on the same logic that you refer to here -- "IIRC, by default,
OpenJPA only does runtime enhancement if classes are enumerated, so this might be indirectly
causing your problem".

In any case, this behavior should be made clear in the documentation.

> PersistenceProviderImpl.createContainerEntityManagerFactory() should not add a ClassTransformerImpl
to PersistenceUnitInfo if <exclude-unlisted-classes>
> --------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-72
>                 URL: http://issues.apache.org/jira/browse/OPENJPA-72
>             Project: OpenJPA
>          Issue Type: Bug
>         Environment: JDK1.5, Win32, openjpa-0.9.0-incubating
>            Reporter: Corey Klaasmeyer
>
> Adding a transformer is unnecessary if classes are enhanced at build time. As far as
I can tell, you specify this by adding the <exclude-unlisted-classes> property to persistence.xml.
This could probably be made more clear by calling the property something like "build-time-enhancement-only"
or "disable-runtime-enhancement". Additionally, this causes a Spring configured JPA to fail
with and IllegalStateException if no LoadTimeWeaver is specified in the LocalContainerEntityManagerFactory.
The relevent code is on line 93 of PersistenceProviderImpl
>     public EntityManagerFactory createContainerEntityManagerFactory(
>         PersistenceUnitInfo pui, Map m) {
>         PersistenceProductDerivation pd = new PersistenceProductDerivation();
>         try {
>             ConfigurationProvider cp = pd.load(pui, m);
>             if (cp == null)
>                 return null;
>             // add enhancer
>             String ctOpts = (String) Configurations.getProperty
>                 (CLASS_TRANSFORMER_OPTIONS, pui.getProperties());
>             pui.addTransformer(new ClassTransformerImpl(cp, ctOpts, 
>                 pui.getNewTempClassLoader()));
>             BrokerFactory factory = Bootstrap.newBrokerFactory(cp, 
>                 pui.getClassLoader());
>             return OpenJPAPersistence.toEntityManagerFactory(factory);
>         } catch (Exception e) {
>             throw PersistenceExceptions.toPersistenceException(e);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message