Versions Compared

Key

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

...

Code Block
java
java
borderStylesolid
titleindex.jsp
<%@ page contentType="text/html" import="javax.naming.Context, javax.naming.InitialContext " %>
<%@ page import="org.apache.geronimo.samples.myphonebookpak.*, javax.naming.* MyPhonebookLocal" %>
<%@ page import="org.apache.geronimo.samples.myphonebookpak.PhoneBook" %>

<%
	    String searchName = "";
	    if (request.getParameter("searchname") != null) {
		searchName=        searchName = request.getParameter("searchname");
	    }
%>

<html>
<html><head><title>Phonebook<<head><title>Phonebook</title></head><body>head>
<body>
<form action="index.jsp">
    <b>Search number</b>:<br>
    Enter name: <input type="text" name="searchname" value="<%=searchName%>">
    <input type="submit" value="Search">
    (Test with <a href="index.jsp?searchname=Joe">Joe</a>)
</form>
<%
	    if (! searchName.equals("")) {
		        String number = "";
		        try {
			            Context context = new InitialContext();
			            MyPhonebookLocal myPhonebookLocal = (MyPhonebookLocal) context.lookup("java:comp/env/ejb/MyPhonebookBean");
			            PhoneBook phonebook = myPhonebookLocal.findByPrimaryKey(searchName);
			if            if (phonebook != null) {
				number =                  number = phonebook.getNumber();
			}
		}
		            }
        }
        catch (Exception e) {
			number=e            number = e.toString();
		}
		        }
        out.println("This is the number returned from the EJB when searching for '" + searchName + "' : " + number);
	    }
%>

</body><body>
</html>

Deployment Plans for EJB

...

persistence.xml will specify the name of the PersistenceUnit. This name is used when referencing for the EntityManagerFactory. I have denoted it as PhonePU. For some reason I could not get it to reference with jta-data-source. So the alternative method is to explicitly specify the ConnectionURL, ConnectionDriverName, and ConnectionUserName. I added an extra property called SynchronizeMappings so that the data in the database will not be 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:             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>
		<class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</class>
		<properties>
			<property name="openjpa.ConnectionURL" value="jdbc:derby:PhoneBookDB" />
			<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" />
			<property name="ConnectionUserName" value="app" />
			        <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>
	<!--
	<jta-data-source>PhoneBookPool</jta-data-source>
	<non-jta-data-source>PhoneBookPool</non-jta-data-source>
	-->
</persistence>

Deployment Plans for the Web-App

...