[
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 figured that part out, no worries, however, I did experience the same
exact problem with the NamedQuery while injecting the EntityManagerFactory
and using emf.createEntityManager(). If you'd like me to post the code and
stack trace I will. I think that's a wild goose chase however.
I think there's a chance you made an assumption that may be incorrect (I
know, I know):
>>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
The thing is my code runs just fine with MultitenantType.SINGLE_TABLE. This
includes a JTA transaction and setting the property _after_ the container
has done container managed persistence injection. The problem _only_ lies
with TENANT_PER_TABLE.
This code runs like a dream. Notice the late call to
em.setProperty("tenant_schema_name", "cust_tables"). Switching this to
em.setProperty("tenant_schema_name", "NON_EXISTANT") results in no Data.
@Entity
@Table(name = "items")
@Multitenant(MultitenantType.SINGLE_TABLE)
@TenantDiscriminatorColumn(contextProperty = "tenant_schema_name")
public class Item implements Serializable {
....
}
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
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.setProperty("tenant_schema_name", "cust_tables2");
log.debug("listActiveItems()");
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());
return results;
}
}
--
View this message in context: http://eclipse.1072660.n5.nabble.com/TENANT-PER-TABLE-Problem-Can-t-compile-Named-Query-tp157573p157590.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.