Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] TENANT_PER_TABLE Problem. Can't compile Named Query.

I believe the issue lies with the container managed persistence context. Can this be changed to persistence unit injection instead?

@PersistenceUnit
private EntityManager em;
I believe the problem is it's too late to set the tenant properties at this point using container managed persistence context since your EM will have already been initialized by the container. Meaning, setting the session name at this point will do nothing as well.

What does your persistence.xml definition look like?

Cheers,
Guy

On 06/02/2013 12:45 PM, exabrial wrote:
Here is that stack trace for the curious:

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class TheHubServiceBean implements TheHubService {
	private static final long serialVersionUID = 1L;

	@Inject
	private Logger log;

	@PersistenceContext
	private EntityManager em;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<Item> listActiveItems() {
		em.getTransaction().begin();
		em.setProperty("eclipselink.session-name", "cust_tables");
		em.setProperty("tenant_schema_name", "cust_tables");
		log.debug("listActiveItems()");
		// TypedQuery<Item> query = em.createNamedQuery("listActiveItems",
Item.class);
		TypedQuery<Item> query =
			em.createQuery("select items from Item items where items.status =
fm.thehub.Status.ACTIVE", Item.class);
		List<Item> results = query.getResultList();
		log.debug("listActiveItems() found {} items", results.size());
		em.getTransaction().commit();
		return results;
	}

}

... 35 more
Feb 06, 2013 11:43:40 AM org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet [rest_647143649] in context with path
[/thehub-web] threw exception [Error processing webservice request] with
root cause
java.lang.IllegalStateException: A JTA EntityManager can not use the
EntityTransaction API.  See JPA 1.0 section 5.5
	at
org.apache.openejb.persistence.JtaEntityManager.getTransaction(JtaEntityManager.java:349)
	at
fm.thehub.service.TheHubServiceBean.listActiveItems(TheHubServiceBean.java:37)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
	at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:128)
	at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:43)
	at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:64)
	at
org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
	at
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176)
	at
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:95)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
	at
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:237)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:189)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:253)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:248)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
	at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)
	at $Proxy96.listActiveItems(Unknown Source)
	at fm.thehub.RestController.listActiveItems(RestController.java:56)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
	at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:167)
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:94)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
	at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
	at
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:236)
	at
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.onMessage(CxfRsHttpListener.java:70)
	at org.apache.openejb.server.rest.RsServlet.service(RsServlet.java:53)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
	at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
	at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)



--
View this message in context: http://eclipse.1072660.n5.nabble.com/TENANT-PER-TABLE-Problem-Can-t-compile-Named-Query-tp157573p157581.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green
            Oracle Oracle is committed to developing practices and products that help protect the environment


Back to the top