[英]What is wrong with this persistence unit configuration?
I am trying to set up a persistence unit in JEE 6 on JBoss AS 6. 我正在尝试在JBoss AS 6的JEE 6中设置一个持久性单元。
The injected EntityManager is always null. 注入的EntityManager始终为null。 I've fiddled around with the configuration quite a bit but can't get anything to work.
我在配置上摆弄了很多,但是什么都无法工作。 I've tried JTA/LOCAL_RESOURCE, I've tried using a unit name in my code the same as in my persistence.xml, but also with the war name prepended, as the log suggests the JNDI name might be that.
我已经尝试过JTA / LOCAL_RESOURCE,已经尝试在我的代码中使用与persistence.xml中相同的单元名称,但是还使用了战争名称,因为日志提示可能是JNDI名称。
I have a mysql-ds.xml file as follows: 我有一个mysql-ds.xml文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>myconnection</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/cog1</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name>bw</user-name>
<password></password>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>5</idle-timeout-minutes>
<exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
<valid-connection-checker-class-name>com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker</valid-connection-checker-class-name>
</local-tx-datasource>
</datasources>
I have a persistence.xml as follows: 我有一个persistence.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"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="myunit" transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:/myconnection</jta-data-source>
<non-jta-data-source>java:/myconnection</non-jta-data-source>
<class>com.cognitura.simulation.dao.model.History</class>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
</persistence>
And I have a bean with the following code in it: 我有一个包含以下代码的bean:
@Stateful
@LocalBean
public class HistoryEJB {
@PersistenceContext(unitName = "myunit")
private EntityManager em;
@EJB
private RealityElement el;
I can see that the RealityElement el is getting injected fine, so I think it's definitely being container-managed? 我可以看到RealityElement el注入良好,所以我认为它肯定是由容器管理的?
Grateful for any ideas! 感谢任何想法!
EDIT: The logs seem to be fine for setting up the 'myunit' unit. 编辑:日志似乎可以用于设置“ myunit”单元。 There is a warning, but I read that it's not important?
有警告,但我读到这并不重要吗?
01:28:06,276 INFO [org.jboss.jpa.deployment.PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitN
ame=cog1.war#myunit
01:28:06,278 INFO [org.hibernate.ejb.Ejb3Configuration] Processing PersistenceUnitInfo [
name: myunit
...]
01:28:06,305 WARN [org.hibernate.ejb.Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec co
rrectly.PersistenceUnitInfo.getNewTempClassLoader() is null.
Seems happy here: 在这里似乎很高兴:
01:28:06,965 INFO [org.hibernate.impl.SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.unit:unitNam
e=cog1.war#myunit
Could it be the jndi name? 可以是jndi名称吗? Try making the following changes in datasource and persistence files
尝试在数据源和持久性文件中进行以下更改
<jndi-name>java:jboss/datasources/employeedb</jndi-name>
<jta-data-source>java:jboss/datasources/employeedb</jta-data-source>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.