if(getDataSource() instanceof org.eclipse.persistence.jpa.JpaEntityManager){//check if the provider is eclipse link
EntityManager entityManager = ((IJpaDataSource)getDataSource()).getEntityManager();
Metamodel classMetadata = entityManager.getMetamodel();
//search the EntityType of the datamartEntityName
for(Iterator it2 = classMetadata.getEntities().iterator(); it2.hasNext(); ) {
EntityType et = (EntityType)it2.next();
String entityName = et.getName();
if(datamartEntityName.equals(entityName)){
Type keyT = et.getIdType();
if (keyT instanceof BasicType) {
//the key has only one field
String name = (et.getId(Object.class)).getName();
if(whereClause==null || whereClause.equals("")){
whereClause = "WHERE ";
}else{
whereClause = whereClause+" AND ";
}
whereClause = whereClause + " "+ entityAlias+"."+name+"="+entityAlias+"."+name;
}else if (keyT instanceof EmbeddableType) {
//the key is a composed key
String keyName = (et.getId(Object.class)).getName();
SingularAttribute keyAttr = (SingularAttribute)(((EmbeddableType) keyT).getDeclaredSingularAttributes().iterator().next());
String name = keyName+"."+keyAttr.getName();
if(whereClause==null || whereClause.equals("")){
whereClause = "WHERE ";
}else{