Hi Guy,
i have tried native queries as well but no chance.
I have seen one weird log line though which is
[#|2012-08-24T10:17:05.006+0300|INFO|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu|_ThreadID=40;_ThreadName=Thread-1;|EclipseLink,
version: Eclipse Persistence Services -
2.0.0.v20091031-r5713|#]
I think this refers to JPA v2.0 because i have eclipselink 2.4
jars in the library and i guess if i was not using 2.4 there
wouldn't be ENUMs for these lines
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type =
TenantTableDiscriminatorType.SCHEMA, contextProperty =
"eclipselink.tenant-id")
what do you think about this log line ?
and this is the code i am executing :
@Entity
@Table(name = "created_report")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type =
TenantTableDiscriminatorType.SCHEMA, contextProperty =
"eclipselink.tenant-id")
@NamedQueries({
@NamedQuery(name = "CreatedReport.find", query = "SELECT r
FROM CreatedReport r ORDER BY r.id DESC"),
....
})
public class CreatedReport implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "date")
@Temporal(TemporalType.TIMESTAMP)
private Date date;
@JoinColumn(name = "reportId", referencedColumnName =
"id")
@ManyToOne(optional = false)
private Report report;
....
}
my @Stateless bean
@Stateless
@Local
public class CreatedReportJPAController {
@Resource
private SessionContext context;
@PersistenceUnit(unitName="multi-tenant-pu")
protected EntityManagerFactory emf;
public List<CreatedReport> findAll() {
List<CreatedReport> resultList = null;
EntityManager em = null;
EntityTransaction tx = null;
Query query;
try {
em = emf.createEntityManager(getProperties());
tx = em.getTransaction();
tx.begin();
em.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT,
getSchema());
query = em.createNamedQuery("Report.find");
resultList = (List<CreatedReport>)
query.getResultList();
} catch (Exception ex) {
tx.rollback();
System.out.println(ex.toString());
} finally {
if (em != null && em.isOpen())
em.close();
}
return resultList;
}
private HashMap getProperties(){
HashMap properties = new HashMap();
properties.put(EntityManagerProperties.JDBC_DRIVER,
"org.postgresql.Driver");
properties.put(EntityManagerProperties.JDBC_URL,
"jdbc:postgresql://localhost:5432/reportDB");
properties.put(EntityManagerProperties.JDBC_USER,
"postgres");
properties.put(EntityManagerProperties.JDBC_PASSWORD,
"");
properties.put(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT,
getSchema());
return properties;
}
private String getSchema() {
returns the schema through
context.getCallerPrincipal().getName() call
}
and here is the important log lines :
after
em = emf.createEntityManager(getProperties());
[#|2012-08-24T10:17:04.794+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:..../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|Begin
deploying Persistence Unit multi-tenant-pu; session
file:.../_multi-tenant-pu;
state Predeployed; factoryCount 1|#]
[#|2012-08-24T10:17:04.936+0300|INFO|glassfishv3.0|org.hibernate.validation.engine.resolver.DefaultTraversableResolver|_ThreadID=40;_ThreadName=Thread-1;|Instantiated
an instance of
org.hibernate.validation.engine.resolver.JPATraversableResolver.|#]
[#|2012-08-24T10:17:04.999+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|property=eclipselink.target-server;
value=SunAS9; translated
value=org.eclipse.persistence.platform.server.sunas.SunAS9ServerPlatform|#]
[#|2012-08-24T10:17:05.001+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|property=eclipselink.logging.level;
value=FINEST; translated value=FINEST|#]
[#|2012-08-24T10:17:05.012+0300|FINE|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|Detected
Vendor platform:
org.eclipse.persistence.platform.database.PostgreSQLPlatform|#]
[#|2012-08-24T10:17:05.015+0300|CONFIG|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.connection|_ThreadID=40;_ThreadName=Thread-1;|connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> ""
connector=>JNDIConnector datasource name=>null
))|#]
[#|2012-08-24T10:17:05.016+0300|CONFIG|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.connection|_ThreadID=40;_ThreadName=Thread-1;|Connected:
jdbc:postgresql://localhost:5432/reportDB?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
User: postgres
Database: PostgreSQL Version: 9.1.4
Driver: PostgreSQL Native Driver Version: PostgreSQL
9.1 JDBC4 (build 902)|#]
[#|2012-08-24T10:17:05.019+0300|CONFIG|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.connection|_ThreadID=40;_ThreadName=Thread-1;|connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> ""
connector=>JNDIConnector datasource name=>null
))|#]
[#|2012-08-24T10:17:05.020+0300|CONFIG|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.connection|_ThreadID=40;_ThreadName=Thread-1;|Connected:
jdbc:postgresql://localhost:5432/reportDB?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
User: postgres
Database: PostgreSQL Version: 9.1.4
Driver: PostgreSQL Native Driver Version: PostgreSQL
9.1 JDBC4 (build 902)|#]
[#|2012-08-24T10:17:05.022+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.sequencing|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|sequencing
connected, state is NoPreallocation_State|#]
[#|2012-08-24T10:17:05.023+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.sequencing|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|sequence
SEQ_GEN_IDENTITY: preallocation size 1|#]
[#|2012-08-24T10:17:05.198+0300|INFO|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu|_ThreadID=40;_ThreadName=Thread-1;|
file:.../_multi-tenant-pu
login successful|#]
[#|2012-08-24T10:17:05.246+0300|FINER|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.jpa_metamodel|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|No
Canonical Metamodel classes found during initialization.|#]
........................
[#|2012-08-24T10:17:07.802+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|End
deploying Persistence Unit multi-tenant-pu; session
file:.../_multi-tenant-pu;
state Deployed; factoryCount 1|#]
[#|2012-08-24T10:17:07.803+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|property=javax.persistence.jdbc.user;
value=postgres|#]
[#|2012-08-24T10:17:07.804+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|property=javax.persistence.jdbc.password;
value=xxxxxx|#]
[#|2012-08-24T10:17:07.805+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|property=javax.persistence.jdbc.driver;
value=org.postgresql.Driver|#]
[#|2012-08-24T10:17:07.806+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|property=javax.persistence.jdbc.url;
value=jdbc:postgresql://localhost:5432/reportDB|#]
after
tx = em.getTransaction();
tx.begin();
[#|2012-08-24T10:20:38.447+0300|FINER|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.connection|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|client
acquired|#]
after
em.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT,
getSchema());
[#|2012-08-24T10:21:10.160+0300|WARNING|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.properties|_ThreadID=40;_ThreadName=Thread-1;|setProperties
method called on EntityManager when active persistence context
already exists therefore properties used to create persistence
context will be ignored. |#]
and after
query.getResultList();
[#|2012-08-24T10:21:50.165+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.query|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|Execute
query ReadAllQuery(name="CreatedReport .find"
referenceClass=CreatedReport sql="SELECT t2.id, t2.date,
t2.reportId FROM created_report t2, report t1 WHERE (t1.id =
t2.reportId)")|#]
[#|2012-08-24T10:21:50.168+0300|FINEST|glassfishv3.0|org.eclipse.persistence.session.file:.../_multi-tenant-pu.connection|_ThreadID=40;_ThreadName=Thread-1;ClassName=null;MethodName=null;|reconnecting
to external connection pool|#]
thanks,
Justin
On 8/23/2012 10:51 AM, Guy Pelletier wrote: