Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

persistence.xml will specify the name of the PersistenceUnit. This name is used when referencing for the EntityManagerFactory. I have denoted it as PhonePU. I added an extra property called SynchronizeMappings so that the data in the database will not be overwritten.

SEE BELOW FOR POSSIBLE SOLUTION

Code Block
xml
xml
borderStylesolid
titlepersistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="PhonePU">
        <description>Phone Book</description>
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <jta-data-source>SampleTxDatasource</jta-data-source>
        <non-jta-data-source>SampleNoTxDatasource</non-jta-data-source>
        <class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</class>
        <properties>
            <property name="openjpa.jdbc.SynchronizeMappings" value="false"/>
        </properties>
    </persistence-unit>
</persistence>

...

To test the sample web application open a browser and type http://localhost:8080/myphonebook.

...

.

...

This app does not use openjpa sequences so apparently you can get by with only a jta-datasource. In my experience apps that do use openjpa sequences to supply primary key values also need a non-jta-datasource. When deploying such a non-jta-datasource check the plan and make sure it says <no-transaction/> rather than <local-transaction/> or <xa-transaction/>.

For this app, use the console to deploy a datasource using the database of your choice. You need to supply a name such as "MyDS" for your datasource. At the end you should have a name for the module your datasource is in such as console.dbpool/MyDS/1.0/rar. You need to do two things so geronimo can hook up to your datasource:

1. Include the module name in the app dependencies so geronimo knows to look in the new datasource module for the datasource. So, the openejb-jar.xml should look something like:

...


<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar
		xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
		xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
		xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
		xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
		xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
	<sys:environment>
		<sys:moduleId>
			<sys:groupId>org.apache.geronimo.samples</sys:groupId>
			<sys:artifactId>MyPhonebookBean</sys:artifactId>
			<sys:version>1.0</sys:version>
			<sys:type>car</sys:type>
		</sys:moduleId>
                <sys:dependencies>
                    <sys:dependency>
			<sys:groupId>console.dbpool</sys:groupId>
			<sys:artifactId>MyDS</sys:artifactId>
			<sys:version>1.0</sys:version>
			<sys:type>rar</sys:type>
                    </sys:dependency>
                </sys:dependencies>
	</sys:environment>
</openejb-jar>

2. specify the name of the datasource in persistence.xml, something like

...