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.

That doesn't surprise me as there is a fundamental difference between SINGLE_TABLE and TABLE_PER_TENANT. When using EM level TABLE_PER_TENANT, behind the scenes, descriptors and queries are cloned per ClientSession and initialized only after all the tenant properties are set. This doesn't need to happen in SINGLE_TABLE where we can use the same queries and dynamically populate the tenant context to filter the results (since it uses a column on the table)

All that being said, it's quite possible you are hitting another bug with TABLE_PER_TABLE and container injection if what I sent you previously doesn't work. Can you enter a bug with your model and test that you have tried along with the stack trace?

Have you tested straight up CRUD operations on the table per tenant multitenant entities? What do you see in the log? (eclipselink.logging.level=FINEST). Is there a problem here or just with the queries?

Cheers,
Guy


On 06/02/2013 1:54 PM, exabrial wrote:
:) 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.
_______________________________________________
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