我正在尝试使用MySQL后端创建一个简单的Web应用程序。我能够在Geronimo中部署我的.ear。但是,当我提交表单以通过OpenJPA将某些内容保存到数据库时,我收到以下错误(下面是我的堆栈跟踪):
引起:org.apache.openjpa.persistence.ArgumentException:必须在ConnectionDriverName属性中指定JDBC驱动程序或DataSource类名。
我的项目是一个企业应用程序项目(AReyes),带有一个Web模块(AReyesAdminWeb)和一个ejb模块(AReyesEJB)。
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="AReyesPersistUnit" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>AReyesMySql</jta-data-source>
<class>com.areyes.entity.Admin</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
</properties>
</persistence-unit>
</persistence>
该文件位于AReyesEJB / ejbModule / META-INF
Caused by: org.apache.openejb.OpenEJBException: Error while creating bean com.areyes.session.AdminManager: Error invoking constructor: public com.areyes.session.AdminManager()
at org.apache.openejb.InjectionProcessor.construct(InjectionProcessor.java:120)
at org.apache.openejb.InjectionProcessor.createInstance(InjectionProcessor.java:83)
at org.apache.openejb.core.stateless.StatelessInstanceManager.ceateInstance(StatelessInstanceManager.java:204)
at org.apache.openejb.core.stateless.StatelessInstanceManager.getInstance(StatelessInstanceManager.java:165)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
... 23 more
Caused by: org.apache.xbean.recipe.ConstructionException: Error invoking constructor: public com.areyes.session.AdminManager()
at org.apache.xbean.recipe.ReflectionUtil$ConstructorFactory.create(ReflectionUtil.java:962)
at org.apache.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:276)
at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96)
at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:61)
at org.apache.openejb.InjectionProcessor.construct(InjectionProcessor.java:118)
... 30 more
Caused by: <openjpa-1.2.2-r422266:898935 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:74)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:784)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:561)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1344)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:505)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:430)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:863)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:854)
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
at com.areyes.session.AdminManager.<init>(AdminManager.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.xbean.recipe.ReflectionUtil$ConstructorFactory.create(ReflectionUtil.java:952)
... 34 more
com.areyes.session.AdminManager是一个@Stateless bean,它已被注入到AReyesAdminWeb中的一个servlet中(带有@EJB anno)。这是建设者:
@Stateless
public class AdminManager implements AdminService {
private EntityManagerFactory fac;
private EntityManager em;
public AdminManager () {
fac = Persistence.createEntityManagerFactory("AReyesPersistUnit", System.getProperties());
em = fac.createEntityManager();
}
我的网络应用程序似乎不知道我的ejb应用程序中的persistence.xml。我想知道我是否正确捆绑了所有内容。
我将此添加到我的application.xml:
<module>
<connector>tranql-connector-mysql-local-1.5.rar</connector>
</module>
然后我将其添加到我的geronimo-application.xml:
<app:module>
<app:connector>tranql-connector-mysql-local-1.5.rar</app:connector>
<app:alt-dd>mysql-plan.xml</app:alt-dd>
</app:module>
在我的EA项目(AReyes)中,我在与META-INF相同的文件夹中添加了mysql-plan.xml。然后我从我的Geronimo文件夹导入了tranql-connector-mysql-local-1.5.rar。
答案 0 :(得分:0)
听起来Web应用程序无法在其类路径中找到persistence.xml。从阅读this thread开始,您可能遇到同样的问题。尝试将persistence.xml移动到以下位置,看看你如何去...
WEB-INF/classes/META-INF/persistence.xml