errors injecting EntityManager having two persistence units in persistence.xml JBoss 7.1.1
icarusdb Sep 2, 2014 2:51 PMwell I have read some posts and examples around there but not a clue
the persistence.xml is
<?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="administration-server">
<jta-data-source>java:jboss/datasources/administration-serverDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="migration-server">
<jta-data-source>java:jboss/datasources/migration-serverDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
the Resources.java is
@Produces | |
@DefaultDB | |
@PersistenceContext(unitName="administration-server") | |
private EntityManager em; |
@Produces | |
@PersistenceContext(unitName="migration-server") | |
@MigrationDB | |
private EntityManager emMigration; |
in my PersonaResourceRESTService I had to remove the prestablish @RequestScoped (javax.enterprise.context.RequestScoped) so the method lookupPersonaByID is properly called, otherwise I get the injection exception
so having my PersonaRepository been @Stateless or @RequestScoped gave errors
injection is not a problem
@Inject @DefaultDB
private EntityManager em;
but trying to create the builder...
final CriteriaBuilder cb = em.getCriteriaBuilder();
gives the same error
org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalArgumentException: JBAS016069: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named administration-server in deployment administration-server.war
org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340)
org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214)
org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)