我想使用Glassfish提供的持久性管理器。
当服务器启动时,持久性单元可以使用_pu1 login successful
的日志条目。
网络服务有效。我可以从客户端访问它,但EntityManager保持NULL
如果我删除@PersistenceContext(unitName = "pu1")
注释,则_pu1 login successful
的日志条目不再出现。如果我改变了unitName
,我会得到一个例外。
我一定错过了一个细节。
设置非常简单:
以下是WebService类的代码(为简洁起见,开头已经省略了):
@LocalBean
@Stateless
@WebService()
public class AlbauInterface implements Serializable {
private Logger logger = Logger.getLogger( getClass().getName() );
@PersistenceContext(unitName = "pu1")
private EntityManager em;
private DataAccess session;
private List<ServiceReport> reports = new ArrayList<ServiceReport>();
private boolean logedIn = false;
@PostConstruct
private void init() {
logger.fine( "initializing" );
}
@PreDestroy
private void finalizer() {
}
@WebMethod
public void login( @WebParam( name = "user", mode = WebParam.Mode.IN ) String user,
@WebParam( name = "password", mode = WebParam.Mode.IN ) String password )
throws WebApplicationException {
logedIn = true;
return;
}
}
这是persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="pu1">
<jta-data-source>jdbc/__default</jta-data-source>
<properties>
<!--Use the java2db feature -->
<property name="eclipselink.ddl-generation" value="create-tables"/>
<!-- Generate the sql specific to Derby database -->
<property name="eclipselink.target-database" value="Derby"/>
</properties>
</persistence-unit>
</persistence>
日志文件包含以下警告,我不明白:
#|2012-03-14T17:57:29.298+0100|WARNING|glassfish3.1.1|org.eclipse.persistence.session.file:/Development/glassfish3/glassfish/domains/domain1/applications/SertalInterface/WEB-INF/classes/_pu1.server|_ThreadID=17;_ThreadName=Thread-3;|Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@d25538].|#]
[#|2012-03-14T17:57:29.298+0100|WARNING|glassfish3.1.1|org.eclipse.persistence.session.file:/Development/glassfish3/glassfish/domains/domain1/applications/SertalInterface/WEB-INF/classes/_pu1.server|_ThreadID=17;_ThreadName=Thread-3;|JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@d25538] from index [0] |#]
[#|2012-03-14T17:57:29.300+0100|WARNING|glassfish3.1.1|org.eclipse.persistence.session.file:/Development/glassfish3/glassfish/domains/domain1/applications/SertalInterface/WEB-INF/classes/_pu1.server|_ThreadID=17;_ThreadName=Thread-3;|JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@9c2a55] from index [1] |#]