Hello there internet community,
So I went into JAVA and started test things localy on my WildFly 8. Everything is OK with maven web projects, looks and works good. Now I decided to go to openshift as the first choice of free cloud for JAVA. I managed to do all needed to get my eclipse and enviorment to work/upload/update server. Then I decided to add MySQL with JPA/Hibernate and localy everything is OK. BUT, when I upload to openshift I get the following error:
2015-05-30 06:18:13,289 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."ROOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."ROOT.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_45]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_45]
Caused by: java.lang.IllegalArgumentException: JBAS016069: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named in deployment ROOT.war
at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:110)
at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:73)
at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:313)
at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:301)
at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createFieldResourceInjection(ResourceInjectionFactory.java:207)
at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createResourceInjections(ResourceInjectionFactory.java:182)
at org.jboss.weld.injection.ResourceInjectionFactory.discoverType(ResourceInjectionFactory.java:405)
at org.jboss.weld.injection.ResourceInjectionFactory.getResourceInjections(ResourceInjectionFactory.java:92)
at org.jboss.weld.injection.producer.ResourceInjector.(ResourceInjector.java:59)
at org.jboss.weld.injection.producer.ResourceInjector.of(ResourceInjector.java:49)
at org.jboss.weld.injection.producer.BeanInjectionTarget.(BeanInjectionTarget.java:62)
at org.jboss.weld.injection.producer.BeanInjectionTarget.createDefault(BeanInjectionTarget.java:46)
at org.jboss.weld.manager.InjectionTargetFactoryImpl.chooseInjectionTarget(InjectionTargetFactoryImpl.java:128)
at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:87)
at org.jboss.weld.bean.ManagedBean.(ManagedBean.java:91)
at org.jboss.weld.bean.ManagedBean.of(ManagedBean.java:71)
at org.jboss.weld.bootstrap.AbstractBeanDeployer.createManagedBean(AbstractBeanDeployer.java:264)
at org.jboss.weld.bootstrap.BeanDeployer.createClassBean(BeanDeployer.java:228)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:78)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:75)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_45]
... 3 more
as you can see the error comes from
JBAS016069: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named in deployment ROOT.war
here is my PersistenceContext injection point:
<pre><code>
@SessionScoped
public class IndexWebBean implements Serializable {
private static final long serialVersionUID = 1L;
@PersistenceContext
EntityManager em;
@Inject
SettingsBean settingsBean;
private boolean isUserAdmin = true;
private String selectedTheme = "aristo";
private String aboutMessage;
private NotificationController notificationController;
public IndexWebBean() {}
@PostConstruct
public void Init() {}
}
</code></pre>
here is persistence.xml:
<pre><code>
<persistence-unit name="ROOT">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
<class>ROOT.ROOT.entity.User</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
</properties>
</persistence-unit>
</code></pre>
standalone.xml:
<pre><code>
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="true" jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQL" enabled="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/crafty</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>com.mysql</driver>
<security>
<user-name>XX</user-name>
<password>XX</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<timeout>
<set-tx-query-timeout>false</set-tx-query-timeout>
<blocking-timeout-millis>0</blocking-timeout-millis>
<idle-timeout-minutes>0</idle-timeout-minutes>
<query-timeout>0</query-timeout>
<use-try-lock>0</use-try-lock>
<allocation-retry>0</allocation-retry>
<allocation-retry-wait-millis>0</allocation-retry-wait-millis>
</timeout>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="com.mysql" module="com.mysql"/>
</drivers>
</datasources>
</code></pre>
(alot of text has been outputed, so quick reminder: localy eveyrthing works like a charm)
So I went with "rhc ssh -a appname" and checked that in wildfly/standalone/deployments/ROOT.war IS compiled in standalone WAR file, while in local system the whole project is folder based - it's not compiled to WAR. That's NOT especialy a bad thing, but the point is that when I unziped the WAR, I checked if folder structure is the same as local folder structure. It seems that it's NOT. There is not META-INF in ROOT.war/WEB-INF/classes where persistence.xml actually stands ... that was a strange one! What I did is to add @PersistenceContext(unitName="ROOT") to em injection point, manualy create that folder (META-INF), manualy upload my persistence.xml from local computer, and rename ROOT.war.failed to ROOT.war.dodeply to re-deploy, and it worked. But then I made some changes to the code localy, again it worked like a charm, published to openshift thru eclipse and still openshift complied my ROOT.war to webarch and META-INF and standalone.xml are nowhere to be found which yet leaded to the same error. So my question is: what am I doing wrong if everything works great localy, and doesn't when is uploaded to openshift? Thanks in advance for your time.
PS.: English is not my native sorry for any errors. I hope everything is readable and understandable. Any more additional info I will provide on demand.