我使用eclipselink与glassfish 3.1和netbeans IDE与mysql 5.5.19作为DB和windows作为操作系统。我使用下面提供的代码编写了一个用户注册模块。用户已注册,我没有收到任何错误,我使用注册用户登录应用程序。问题是,我无法在mysql中查看我创建的表。我通过命令提示符连接到mysql后使用了“show tables”命令。 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="PerfumePU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>persistence.UserAddress</class>
<class>persistence.UserDetails</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.target-database" value="MYSQL"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/Perfume"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
EJB远程接口是:
@Remote
public interface RegisterEJBRemote {
boolean CreateUser(UserDetails user,UserAddress userAddress);
}
EJB类是:
@Stateless
@LocalBean
public class RegisterEJB implements RegisterEJBRemote{
@PersistenceContext(unitName="PerfumePU")
private EntityManager em;
public boolean CreateUser(UserDetails userDetails,UserAddress userAddress){
boolean returnValue=true;
try{
em.persist(userDetails);
em.persist(userAddress);
}catch(Exception ex){
//some code
}
return returnValue;
}
}
客户端是托管bean(使用JSF 2.0)
@ManagedBean
public class Register extends AbstractBean{
@EJB
private RegisterEJB registerEJB;
public String RegisterAction(){
String result="failure";
//Creating the entities
UserAddress userAddress=new UserAddress( ) ;
UserDetails userDetails=new UserDetails();
boolean returnValue=registerEJB.CreateUser(userDetails,userAddress);
//more code
}
}
我是JPA的新手,我第一次使用EJB。我真的很想知道我的桌子在哪里。我手动创建了名为Perfume的数据库。