openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Adams <matt...@matthewadams.me>
Subject Re: How to use custom persistence.xml & orm.xml files?
Date Thu, 29 Apr 2010 19:33:19 GMT
Ok, I'll try to explain my setup.

I have a Spring-based WAR that depends on JAR that has entities in it,
and I want the WAR to not have to be cracked open in order to
configure it for a particular environment -- I want all configuration,
including data sources & JPA mappings, to be externalized into
properties files outside the WAR.

Here's my desired directory structure:

(webapp root directory)
  WEB-INF/
    spring/
      app-config.xml
      db-config.xml
      jpa-config.xml
      ...other spring config files...
    lib/
      case-model-1.1.0-SNAPSHOT.jar
      ...other jars...

(separate resource directory made available to webapp by jetty or tomcat)
  linx2/
    linx2.properties
    hsqldb-memory-openjpa.properties
    hsqldb-memory-case-model-orm.xml
    hsqldb-memory-case-model-persistence.xml

With this configuration, I can specify in linx2.properties that
linx2.db.type=hsqldb-memory, which will cause the
LocalContainerEntityManagerFactoryBean in jpa-config.xml to use the
right files (see file jpa-config.xml below).

For the life of me, I can't get this to work.  Given this file layout,
what should be in the following files if I want OpenJPA to build the
schema dynamically at runtime?  OpenJPA appears to find all my
classes' metadata, but it just doesn't generate the schema.  (I've
attached the zipped log, but I don't know if it'll survive the mailing
list server).

hsqldb-memory-openjpa.properties
hsqldb-memory-case-model-persistence.xml
hsqldb-memory-case-model-orm.xml

Here's what I currently have for hsqldb-memory-openjpa.properties:

openjpa.AutoDetach=commit
openjpa.DetachState=fgs
openjpa.QueryCache=false
openjpa.jdbc.SubclassFetchMode=none
openjpa.jdbc.EagerFetchMode=none
openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=false,Indexes=false)
openjpa.Log=DefaultLevel=TRACE
openjpa.MetaDataFactory=jpa(ClasspathScan=case-model-1.1.0-SNAPSHOT,Resources=hsqldb-memory-case-model-orm.xml)
openjpa.RuntimeUnenhancedClasses=unsupported

Here's what I currently have for hsqldb-memory-case-model-persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	version="1.0">
	<persistence-unit name="case-model">
		<provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
	</persistence-unit>
</persistence>

Here's what I currently have for hsqldb-memory-case-model-orm.xml:

<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
        http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
	version="1.0">
	
	<!--  empty for now, but will need to customize -->

</entity-mappings>

Here's my WEB-INF/spring/jpa-config.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                           http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
                           http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
                           http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="case-model" />
		<property name="persistenceXmlLocation"
			value="classpath:/linx2/${linx2.db.type}-case-model-persistence.xml" />
		<property name="jpaProperties">
			<util:properties
				location="classpath:/linx2/${linx2.db.type}-openjpa.properties" />
		</property>
		<property name="dataSource" ref="dataSource" />
		<property name="jpaDialect">
			<bean class="org.springframework.orm.jpa.vendor.OpenJpaDialect"/>
		</property>
		<property name="jpaVendorAdapter">
		  <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
              <property name="showSql" value="true"/>
		  </bean>
		</property>
	</bean>

	<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
		<property name="dataSource" ref="dataSource" />
		<property name="jpaDialect">
		  <bean class="org.springframework.orm.jpa.vendor.OpenJpaDialect"/>
		</property>
	</bean>

	<tx:annotation-driven transaction-manager="transactionManager"
		proxy-target-class="true" />

</beans>

If anyone has any suggestions on what my various config files should
contain, or where they should be located, please let me know.

Thanks,
Matthew

On Thu, Apr 29, 2010 at 11:34 AM, Rick Curtis <curtisr7@gmail.com> wrote:
> I not going to claim that I grok your entire setup, but I'm pretty sure that
> you need to move your persistence.xml files to the META-INF directory.
> --
> Thanks,
> Rick
>
> On Wed, Apr 28, 2010 at 5:59 PM, Matthew Adams <matthew@matthewadams.me>wrote:
>
>> Oops, first sentence should have read:
>>
>> OpenJPA 1.2.2 is not generating my schema at RUN time...
>>
>> On Wed, Apr 28, 2010 at 3:48 PM, Matthew Adams <matthew@matthewadams.me>
>> wrote:
>> > OpenJPA 1.2.2 is not generating my schema at compile time
>>
>> If anyone can help, I'd still appreciate it.  :)
>>
>> -matthew
>>
>



-- 
mailto:matthew@matthewadams.me
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:matthewadams12@gmail.com
msn:matthew@matthewadams.me
http://matthewadams.me
http://www.linkedin.com/in/matthewadams

Mime
View raw message