Please help, this is driving me crazy. I've been researching this for hours, and couldn't find an example that matches my situation.
I'm writing a very simple Java EE App which authenticates users from a standalone client. In Netbeans 7.3, I have a Java EE application project with an EJB module, an application client project, and a separate java class library for the bean's remote interface and the entities.
The EJB module has one bean (AccountsBean.java), the class library project has the bean's remote interface (AccountsBeanRemote.java), the entity (Account.java) and the persistence.xml file. Here's a picture of the project layout so you can see it clearly: http://snag.gy/EoyQa.jpg
I want to pass Account instances to the client.
I'm using Glassfish 3.1 and Java DB (Derby).
I have 3 databases: AccountsTest (which I want to use here), sample, and sun-appserv-samples (these two are created during the Glassfish install).
The problem is that is doesn't matter what database connection I specify in persistence.xml, the table always gets created in the sample database sun-appserv-samples. It seems to me that the bean ignores the persistence.xml file. Maybe the problem is that persistence.xml is in a separate project from the bean, but this is the only way the IDE lets me do it if I want to pass Account instances to the remote client.
Here's my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
<persistence-unit name="LoginTest-libPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>logintest.lib.Account</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/AccountsTest"/>
<property name="javax.persistence.jdbc.password" value="app"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user" value="app"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
And AccountsBean.java:
@Stateless
public class AccountsBean implements AccountsBeanRemote {
@PersistenceContext(unitName = "LoginTest-libPU")
EntityManager em;
@Override
public Account create(String name, String password) {
...
}
@Override
public void remove(int id) {
...
}
@Override
public boolean checkPassword(int id, String password) {
...
}
}
Account.java:
@Entity
@Table(name = "ACCOUNTS")
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String password;
public Account() {
}
...other methods
I guess I didn't configure the EntityManager correctly, but where should I put persistence.xml? If I put it in the EJB module, I also have to put the entities in the EJB module, and they will be inaccessible to the client.
Thanks in advance!