Passing parameters to be used in Customizer [message #673589] |
Tue, 24 May 2011 08:17 |
Pedro Oliveira Messages: 6 Registered: May 2011 |
Junior Member |
|
|
Hi, I'm trying to define a Customizer to an Eclipselink entity, using the annotation @Customizer. The code of the customizer is working well, however I need to pass a parameter to be used in a subquery inside the customizer. In the ReportQuery.setSelectionCriteria I put an Expression like: subQuery.getExpressionBuilder().getTable("User").getField("id").equal(new PropertyValue("customID"));
The class PropertyValue is an instanceof ParameterExpression which will be called when the customizer is invoked (the method "public Object getValue(AbstractRecord translationRow, AbstractSession session)" is called). I'm trying to get a property passed by the EntityManager, however I only receive the properties defined in persistence.xml. I use the following code to create the EntityManager is each query:
...
private static EntityManagerFactory factory;
...
public synchronized static EntityManager getEntityManager() {
if (factory == null) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
}
EntityManager entityManager = factory.createEntityManager();
}
With the previous code, a new EntityManager is created for each query, however when the "getValue" of ParameterExpression is called, only the ServerSession (the one created by the "Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);") is received and only the properties defined in the persistence.xml are accessible.
How can I pass a property/parameter value to the Customizer that will be supplied dynamically per EntityManager in each query?
Many thanks,
Pedro Oliveira
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03023 seconds