nus-yam/ex-repair huggingface dataset:
Program: 176255
Project: 176255
Buggy source:
/** 
 * Populate metadata.
 * @param < X > the generic type
 * @param < T > the generic type
 * @param metadata the metadata
 * @param clazz the clazz
 */
private <X extends Class,T extends Object>void populateMetadata(EntityMetadata metadata,Class<X> clazz,Map puProperties){
  Table table=clazz.getAnnotation(Table.class);
  metadata.setTableName(table.name());
  addNamedNativeQueryMetadata(clazz);
  String schemaStr=table.schema();
  MetadataUtils.setSchemaAndPersistenceUnit(metadata,schemaStr,puProperties);
  if (metadata.getPersistenceUnit() != null) {
    MetaModelBuilder<X,T> metaModelBuilder=KunderaMetadata.INSTANCE.getApplicationMetadata().getMetaModelBuilder(metadata.getPersistenceUnit());
    metaModelBuilder.process(clazz);
    for (    Field f : clazz.getDeclaredFields()) {
      if (f != null && !Modifier.isStatic(f.getModifiers()) && !Modifier.isTransient(f.getModifiers()) && !f.isAnnotationPresent(Transient.class)) {
        metaModelBuilder.construct(clazz,f);
        onIdAttribute(metaModelBuilder,metadata,clazz,f);
        onFamilyType(metadata,clazz,f);
        onJPAColumnMapping(metaModelBuilder,metadata,f);
        addRelationIntoMetadata(clazz,f,metadata);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Populate metadata.
 * @param < X > the generic type
 * @param < T > the generic type
 * @param metadata the metadata
 * @param clazz the clazz
 */
private <X extends Class,T extends Object>void populateMetadata(EntityMetadata metadata,Class<X> clazz,Map puProperties){
  if (metadata.getPersistenceUnit() != null) {
    MetaModelBuilder<X,T> metaModelBuilder=KunderaMetadata.INSTANCE.getApplicationMetadata().getMetaModelBuilder(metadata.getPersistenceUnit());
    metaModelBuilder.process(clazz);
    for (    Field f : clazz.getDeclaredFields()) {
      if (f != null && !Modifier.isStatic(f.getModifiers()) && !Modifier.isTransient(f.getModifiers()) && !f.isAnnotationPresent(Transient.class)) {
        metaModelBuilder.construct(clazz,f);
        onIdAttribute(metaModelBuilder,metadata,clazz,f);
        onFamilyType(metadata,clazz,f);
        onJPAColumnMapping(metaModelBuilder,metadata,f);
        addRelationIntoMetadata(clazz,f,metadata);
      }
    }
  }
}
Program: 176256
Project: 176256
Buggy source:
/** 
 * Checks the validity of a class for Cassandra entity.
 * @param clazz validates this class
 * @return returns 'true' if valid
 */
@Override public final void validate(final Class<?> clazz){
  if (classes.contains(clazz)) {
    return;
  }
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + clazz.getName());
  if (!clazz.isAnnotationPresent(Entity.class)) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  if (!clazz.isAnnotationPresent(Table.class)) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  try {
    clazz.getConstructor();
  }
 catch (  NoSuchMethodException nsme) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  List<Field> keys=new ArrayList<Field>();
  for (  Field field : clazz.getDeclaredFields()) {
    if (field.isAnnotationPresent(Id.class) && field.isAnnotationPresent(EmbeddedId.class)) {
      throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
    }
    if (field.isAnnotationPresent(Id.class)) {
      keys.add(field);
      if (field.isAnnotationPresent(GeneratedValue.class)) {
        validateGeneratedValueAnnotation(clazz,field);
      }
    }
 else     if (field.isAnnotationPresent(EmbeddedId.class)) {
      keys.add(field);
    }
  }
  if (keys.size() < 0) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
 else   if (keys.size() > 1) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  classes.add(clazz);
}

Fixed version (ground truth):
/** 
 * Checks the validity of a class for Cassandra entity.
 * @param clazz validates this class
 * @return returns 'true' if valid
 */
@Override public final void validate(final Class<?> clazz){
  if (classes.contains(clazz)) {
    return;
  }
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + clazz.getName());
  if (!clazz.isAnnotationPresent(Entity.class)) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  try {
    clazz.getConstructor();
  }
 catch (  NoSuchMethodException nsme) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  List<Field> keys=new ArrayList<Field>();
  for (  Field field : clazz.getDeclaredFields()) {
    if (field.isAnnotationPresent(Id.class) && field.isAnnotationPresent(EmbeddedId.class)) {
      throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
    }
    if (field.isAnnotationPresent(Id.class)) {
      keys.add(field);
      if (field.isAnnotationPresent(GeneratedValue.class)) {
        validateGeneratedValueAnnotation(clazz,field);
      }
    }
 else     if (field.isAnnotationPresent(EmbeddedId.class)) {
      keys.add(field);
    }
  }
  if (keys.size() < 0) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
 else   if (keys.size() > 1) {
    throw new InvalidEntityDefinitionException(clazz.getName() + "String_Node_Str");
  }
  classes.add(clazz);
}
Program: 176258
Project: 176258
Buggy source:
/** 
 * @throws java.lang.Exception
 */
@Before public void setUp() throws Exception {
  CassandraCli.cassandraSetUp();
  KunderaMetadata.INSTANCE.setApplicationMetadata(null);
  mongoProperties.put("String_Node_Str","String_Node_Str");
  cassandraProperties.put("String_Node_Str","String_Node_Str");
  puPropertiesMap.put("String_Node_Str",mongoProperties);
  puPropertiesMap.put("String_Node_Str",cassandraProperties);
  emf=Persistence.createEntityManagerFactory(_PU,puPropertiesMap);
  em=emf.createEntityManager();
}

Fixed version (ground truth):
/** 
 * @throws java.lang.Exception
 */
@Before public void setUp() throws Exception {
  CassandraCli.cassandraSetUp();
  KunderaMetadata.INSTANCE.setApplicationMetadata(null);
  mongoProperties.put("String_Node_Str","String_Node_Str");
  cassandraProperties.put("String_Node_Str","String_Node_Str");
  properties.put("String_Node_Str","String_Node_Str");
  puPropertiesMap.put("String_Node_Str",mongoProperties);
  puPropertiesMap.put("String_Node_Str",cassandraProperties);
  puPropertiesMap.put("String_Node_Str",properties);
  puPropertiesMap.put("String_Node_Str",properties);
  emf=Persistence.createEntityManagerFactory(_PU,puPropertiesMap);
  em=emf.createEntityManager();
}
Program: 176259
Project: 176259
Buggy source:
/** 
 * The Constructor.
 * @param property the property
 * @param condition the condition
 * @param value the value
 */
public FilterClause(String property,String condition,Object value){
  super();
  this.property=property;
  this.condition=condition;
  this.value=KunderaQuery.getValue(value);
}

Fixed version (ground truth):
/** 
 * The Constructor.
 * @param property the property
 * @param condition the condition
 * @param value the value
 */
public FilterClause(String property,String condition,Object value){
  super();
  this.property=property;
  this.condition=condition.trim();
  this.value=KunderaQuery.getValue(value);
}
Program: 176260
Project: 176260
Buggy source:
@Override protected List<Object> populateEntities(EntityMetadata m,Client client){
  MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  EntityType entity=metaModel.entity(m.getEntityClazz());
  FilterBuilder preIntraFilter=null;
  FilterBuilder preInterFilter=null;
  String interFilter=null;
  for (  Object o : getKunderaQuery().getFilterClauseQueue()) {
    if (o instanceof FilterClause) {
      FilterClause clause=((FilterClause)o);
      FilterBuilder currentFilter=getFilter(clause,m,entity);
      if (interFilter != null) {
        if (interFilter.equalsIgnoreCase("String_Node_Str")) {
          preInterFilter=new AndFilterBuilder(preIntraFilter,currentFilter);
        }
 else         if (interFilter.equalsIgnoreCase("String_Node_Str")) {
          preInterFilter=new OrFilterBuilder(preIntraFilter,currentFilter);
        }
      }
      preIntraFilter=currentFilter;
    }
 else {
      String opr=o.toString();
      interFilter=opr;
    }
  }
  return ((ESClient)client).executeQuery(preInterFilter != null ? preInterFilter : preIntraFilter,m);
}

Fixed version (ground truth):
@Override protected List<Object> populateEntities(EntityMetadata m,Client client){
  MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  EntityType entity=metaModel.entity(m.getEntityClazz());
  FilterBuilder preIntraFilter=null;
  FilterBuilder preInterFilter=null;
  String interFilter=null;
  for (  Object o : getKunderaQuery().getFilterClauseQueue()) {
    if (o instanceof FilterClause) {
      FilterClause clause=((FilterClause)o);
      FilterBuilder currentFilter=getFilter(clause,m,entity);
      if (interFilter != null) {
        if (interFilter.equalsIgnoreCase("String_Node_Str")) {
          preInterFilter=new AndFilterBuilder(preIntraFilter,currentFilter);
        }
 else         if (interFilter.equalsIgnoreCase("String_Node_Str")) {
          preInterFilter=new OrFilterBuilder(preIntraFilter,currentFilter);
        }
      }
      preIntraFilter=currentFilter;
    }
 else {
      String opr=o.toString();
      interFilter=opr.trim();
    }
  }
  return ((ESClient)client).executeQuery(preInterFilter != null ? preInterFilter : preIntraFilter,m);
}
Program: 176263
Project: 176263
Buggy source:
private OracleNoSQLQueryInterpreter translateQuery(Queue clauseQueue,EntityMetadata entityMetadata){
  OracleNoSQLQueryInterpreter interpreter=new OracleNoSQLQueryInterpreter(getColumns(getKunderaQuery().getResult(),entityMetadata));
  interpreter.setClauseQueue(clauseQueue);
  String operatorWithIdClause=null;
  boolean idClauseFound=false;
  for (  Object clause : clauseQueue) {
    if (clause.getClass().isAssignableFrom(FilterClause.class) && !idClauseFound) {
      String columnName=((FilterClause)clause).getProperty();
      SingularAttribute idAttribute=entityMetadata.getIdAttribute();
      if (columnName.equals(((AbstractAttribute)idAttribute).getJPAColumnName())) {
        interpreter.setFindById(true);
        Object keyObj=PropertyAccessorHelper.fromSourceToTargetClass(((AbstractAttribute)idAttribute).getBindableJavaType(),String.class,((FilterClause)clause).getValue());
        interpreter.setRowKey(keyObj);
        idClauseFound=true;
      }
    }
 else     if (clause instanceof String) {
      operatorWithIdClause=clause.toString();
    }
    if (idClauseFound && operatorWithIdClause != null) {
      break;
    }
  }
  interpreter.setOperatorWithRowKey(operatorWithIdClause);
  return interpreter;
}

Fixed version (ground truth):
private OracleNoSQLQueryInterpreter translateQuery(Queue clauseQueue,EntityMetadata entityMetadata){
  OracleNoSQLQueryInterpreter interpreter=new OracleNoSQLQueryInterpreter(getColumns(getKunderaQuery().getResult(),entityMetadata));
  interpreter.setClauseQueue(clauseQueue);
  String operatorWithIdClause=null;
  boolean idClauseFound=false;
  for (  Object clause : clauseQueue) {
    if (clause.getClass().isAssignableFrom(FilterClause.class) && !idClauseFound) {
      String columnName=((FilterClause)clause).getProperty();
      SingularAttribute idAttribute=entityMetadata.getIdAttribute();
      if (columnName.equals(((AbstractAttribute)idAttribute).getJPAColumnName())) {
        interpreter.setFindById(true);
        Object keyObj=PropertyAccessorHelper.fromSourceToTargetClass(((AbstractAttribute)idAttribute).getBindableJavaType(),String.class,((FilterClause)clause).getValue());
        interpreter.setRowKey(keyObj);
        idClauseFound=true;
      }
    }
 else     if (clause instanceof String) {
      operatorWithIdClause=clause.toString().trim();
    }
    if (idClauseFound && operatorWithIdClause != null) {
      break;
    }
  }
  interpreter.setOperatorWithRowKey(operatorWithIdClause);
  return interpreter;
}
Program: 176265
Project: 176265
Buggy source:
/** 
 * update method update schema and table for the list of tableInfos
 * @param tableInfos list of TableInfos.
 */
protected void update(List<TableInfo> tableInfos){
  for (  TableInfo tableInfo : tableInfos) {
    DBObject options=setCollectionProperties(tableInfo);
    getDBName();
    DB db=mongo.getDB(databaseName);
    DBCollection collection=null;
    if (!db.collectionExists(tableInfo.getTableName())) {
      collection=db.createCollection(tableInfo.getTableName(),options);
    }
    collection=collection != null ? collection : db.getCollection(tableInfo.getTableName());
    boolean isCappedCollection=isCappedCollection(tableInfo);
    if (!isCappedCollection) {
      createIndexes(tableInfo,collection);
    }
  }
}

Fixed version (ground truth):
/** 
 * update method update schema and table for the list of tableInfos
 * @param tableInfos list of TableInfos.
 */
protected void update(List<TableInfo> tableInfos){
  for (  TableInfo tableInfo : tableInfos) {
    DBObject options=setCollectionProperties(tableInfo);
    DB db=mongo.getDB(databaseName);
    DBCollection collection=null;
    if (!db.collectionExists(tableInfo.getTableName())) {
      collection=db.createCollection(tableInfo.getTableName(),options);
    }
    collection=collection != null ? collection : db.getCollection(tableInfo.getTableName());
    boolean isCappedCollection=isCappedCollection(tableInfo);
    if (!isCappedCollection) {
      createIndexes(tableInfo,collection);
    }
  }
}
Program: 176266
Project: 176266
Buggy source:
/** 
 * create method creates schema and table for the list of tableInfos.
 * @param tableInfos list of TableInfos.
 */
protected void create(List<TableInfo> tableInfos){
  for (  TableInfo tableInfo : tableInfos) {
    DBObject options=setCollectionProperties(tableInfo);
    getDBName();
    DB db=mongo.getDB(databaseName);
    if (db.collectionExists(tableInfo.getTableName())) {
      db.getCollection(tableInfo.getTableName()).drop();
    }
    DBCollection collection=db.createCollection(tableInfo.getTableName(),options);
    boolean isCappedCollection=isCappedCollection(tableInfo);
    if (!isCappedCollection) {
      createIndexes(tableInfo,collection);
    }
  }
}

Fixed version (ground truth):
/** 
 * create method creates schema and table for the list of tableInfos.
 * @param tableInfos list of TableInfos.
 */
protected void create(List<TableInfo> tableInfos){
  for (  TableInfo tableInfo : tableInfos) {
    DBObject options=setCollectionProperties(tableInfo);
    DB db=mongo.getDB(databaseName);
    if (db.collectionExists(tableInfo.getTableName())) {
      db.getCollection(tableInfo.getTableName()).drop();
    }
    DBCollection collection=db.createCollection(tableInfo.getTableName(),options);
    boolean isCappedCollection=isCappedCollection(tableInfo);
    if (!isCappedCollection) {
      createIndexes(tableInfo,collection);
    }
  }
}
Program: 176268
Project: 176268
Buggy source:
/** 
 * On executeUpdate.
 * @return zero
 */
@Override protected int onExecuteUpdate(){
  EntityMetadata m=getEntityMetadata();
  if (KunderaMetadata.INSTANCE.getApplicationMetadata().isNative(getJPAQuery())) {
    ((CassandraClientBase)persistenceDelegeator.getClient(m)).executeQuery(KunderaMetadata.INSTANCE.getApplicationMetadata().getQuery(getJPAQuery()),m.getEntityClazz(),null);
  }
 else   if (kunderaQuery.isDeleteUpdate()) {
    if (!isQueryConvertibleToCQL(kunderaQuery)) {
      List result=getResultList();
      return result != null ? result.size() : 0;
    }
 else {
      String query=null;
      if (kunderaQuery.isUpdateClause()) {
        query=createUpdateQuery(kunderaQuery);
      }
 else {
        query=createDeleteQuery(kunderaQuery);
      }
      return ((CassandraClientBase)persistenceDelegeator.getClient(m)).executeUpdateDeleteQuery(query);
    }
  }
  return 0;
}

Fixed version (ground truth):
/** 
 * On executeUpdate.
 * @return zero
 */
@Override protected int onExecuteUpdate(){
  EntityMetadata m=getEntityMetadata();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  String query=appMetadata.getQuery(getJPAQuery());
  boolean isNative=kunderaQuery.isNative();
  if (isNative) {
    ((CassandraClientBase)persistenceDelegeator.getClient(m)).executeQuery(query != null ? query : getJPAQuery(),m.getEntityClazz(),null);
  }
 else   if (kunderaQuery.isDeleteUpdate()) {
    if (!isQueryConvertibleToCQL(kunderaQuery)) {
      List result=getResultList();
      return result != null ? result.size() : 0;
    }
 else {
      query=null;
      if (kunderaQuery.isUpdateClause()) {
        query=createUpdateQuery(kunderaQuery);
      }
 else {
        query=createDeleteQuery(kunderaQuery);
      }
      return ((CassandraClientBase)persistenceDelegeator.getClient(m)).executeUpdateDeleteQuery(query);
    }
  }
  return 0;
}
Program: 176269
Project: 176269
Buggy source:
@SuppressWarnings("String_Node_Str") @Override protected List<Object> recursivelyPopulateEntities(EntityMetadata m,Client client){
  List<EnhanceEntity> ls=null;
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  if (appMetadata.isNative(getJPAQuery())) {
    ls=(List<EnhanceEntity>)((CassandraClientBase)client).executeQuery(appMetadata.getQuery(getJPAQuery()),m.getEntityClazz(),null);
  }
 else   if (!appMetadata.isNative(getJPAQuery()) && ((CassandraClientBase)client).isCql3Enabled(m)) {
    ls=((CassandraClientBase)client).executeQuery(onQueryOverCQL3(m,client,metaModel,m.getRelationNames()),m.getEntityClazz(),m.getRelationNames());
  }
 else {
    boolean useInvertedIndex=CassandraIndexHelper.isInvertedIndexingApplicable(m,MetadataUtils.useSecondryIndex(((ClientBase)client).getClientMetadata()));
    Map<Boolean,List<IndexClause>> ixClause=MetadataUtils.useSecondryIndex(((ClientBase)client).getClientMetadata()) ? prepareIndexClause(m,useInvertedIndex) : null;
    if (useInvertedIndex && !getKunderaQuery().getFilterClauseQueue().isEmpty()) {
      ls=((CassandraEntityReader)getReader()).readFromIndexTable(m,client,ixClause);
    }
 else {
      ((CassandraEntityReader)getReader()).setConditions(ixClause);
      ls=reader.populateRelation(m,client,isSingleResult ? 1 : this.maxResult);
    }
  }
  return setRelationEntities(ls,client,m);
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Override protected List<Object> recursivelyPopulateEntities(EntityMetadata m,Client client){
  List<EnhanceEntity> ls=null;
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  String query=appMetadata.getQuery(getJPAQuery());
  boolean isNative=kunderaQuery.isNative();
  if (isNative) {
    ls=(List<EnhanceEntity>)((CassandraClientBase)client).executeQuery(query != null ? query : getJPAQuery(),m.getEntityClazz(),null);
  }
 else   if (!isNative && ((CassandraClientBase)client).isCql3Enabled(m)) {
    ls=((CassandraClientBase)client).executeQuery(onQueryOverCQL3(m,client,metaModel,m.getRelationNames()),m.getEntityClazz(),m.getRelationNames());
  }
 else {
    boolean useInvertedIndex=CassandraIndexHelper.isInvertedIndexingApplicable(m,MetadataUtils.useSecondryIndex(((ClientBase)client).getClientMetadata()));
    Map<Boolean,List<IndexClause>> ixClause=MetadataUtils.useSecondryIndex(((ClientBase)client).getClientMetadata()) ? prepareIndexClause(m,useInvertedIndex) : null;
    if (useInvertedIndex && !getKunderaQuery().getFilterClauseQueue().isEmpty()) {
      ls=((CassandraEntityReader)getReader()).readFromIndexTable(m,client,ixClause);
    }
 else {
      ((CassandraEntityReader)getReader()).setConditions(ixClause);
      ls=reader.populateRelation(m,client,isSingleResult ? 1 : this.maxResult);
    }
  }
  return setRelationEntities(ls,client,m);
}
Program: 176271
Project: 176271
Buggy source:
/** 
 * Test create native query.
 */
@Test public void testCreateNativeQuery(){
  EntityManagerFactoryImpl emf=getEntityManagerFactory();
  EntityManager em=emf.createEntityManager();
  String nativeSql="String_Node_Str";
  QueryImpl q=(QueryImpl)em.createNativeQuery(nativeSql,CassandraEntitySample.class);
  Assert.assertEquals(nativeSql,q.getJPAQuery());
  Assert.assertEquals(true,KunderaMetadata.INSTANCE.getApplicationMetadata().isNative(nativeSql));
}

Fixed version (ground truth):
/** 
 * Test create native query.
 */
@Test public void testCreateNativeQuery(){
  EntityManagerFactoryImpl emf=getEntityManagerFactory();
  EntityManager em=emf.createEntityManager();
  String nativeSql="String_Node_Str";
  QueryImpl q=(QueryImpl)em.createNativeQuery(nativeSql,CassandraEntitySample.class);
  Assert.assertEquals(nativeSql,q.getJPAQuery());
}
Program: 176272
Project: 176272
Buggy source:
/** 
 * Creates the query.
 * @param jpaQuery the jpa query
 * @return the query
 */
Query createQuery(String jpaQuery){
  Query query=new QueryResolver().getQueryImplementation(jpaQuery,this);
  return query;
}

Fixed version (ground truth):
/** 
 * Creates the query.
 * @param jpaQuery the jpa query
 * @return the query
 */
Query createQuery(String jpaQuery){
  return getQueryInstance(jpaQuery,false,null);
}
Program: 176273
Project: 176273
Buggy source:
/** 
 * Returns entity metadata, in case of native query mapped class is present within application metadata.
 * @return entityMetadata entity metadata.
 */
protected EntityMetadata getEntityMetadata(){
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  EntityMetadata m=null;
  if (appMetadata.isNative(getJPAQuery())) {
    Class clazz=appMetadata.getMappedClass(getJPAQuery());
    m=KunderaMetadataManager.getEntityMetadata(clazz);
  }
 else {
    m=kunderaQuery.getEntityMetadata();
  }
  return m;
}

Fixed version (ground truth):
/** 
 * Returns entity metadata, in case of native query mapped class is present within application metadata.
 * @return entityMetadata entity metadata.
 */
protected EntityMetadata getEntityMetadata(){
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  EntityMetadata m=null;
  String query=appMetadata.getQuery(getJPAQuery());
  boolean isNative=kunderaQuery.isNative();
  if (isNative) {
    Class clazz=kunderaQuery.getEntityClass();
    m=KunderaMetadataManager.getEntityMetadata(clazz);
  }
 else {
    m=kunderaQuery.getEntityMetadata();
  }
  return m;
}
Program: 176274
Project: 176274
Buggy source:
/** 
 * Gets the query implementation.
 * @param jpaQuery the jpa query
 * @param persistenceDelegator the persistence delegator
 * @param persistenceUnits the persistence units
 * @return the query implementation
 */
public Query getQueryImplementation(String jpaQuery,PersistenceDelegator persistenceDelegator){
  if (jpaQuery == null) {
    throw new QueryHandlerException("String_Node_Str");
  }
  kunderaQuery=new KunderaQuery();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  String mappedQuery=appMetadata.getQuery(jpaQuery);
  boolean isNative=appMetadata.isNative(jpaQuery);
  EntityMetadata m=null;
  if (!isNative) {
    KunderaQueryParser parser=new KunderaQueryParser(kunderaQuery,mappedQuery != null ? mappedQuery : jpaQuery);
    parser.parse();
    kunderaQuery.postParsingInit();
    m=kunderaQuery.getEntityMetadata();
  }
 else {
    Class mappedClass=appMetadata.getMappedClass(jpaQuery);
    m=KunderaMetadataManager.getEntityMetadata(mappedClass);
  }
  Query query=null;
  try {
    query=getQuery(jpaQuery,persistenceDelegator,m);
  }
 catch (  Exception e) {
    log.error(e.getMessage());
    throw new QueryHandlerException(e);
  }
  return query;
}

Fixed version (ground truth):
/** 
 * Gets the query implementation.
 * @param jpaQuery the jpa query
 * @param persistenceDelegator the persistence delegator
 * @param persistenceUnits the persistence units
 * @return the query implementation
 */
public Query getQueryImplementation(String jpaQuery,PersistenceDelegator persistenceDelegator,Class mappedClass,boolean isNative){
  if (jpaQuery == null) {
    throw new QueryHandlerException("String_Node_Str");
  }
  KunderaQuery kunderaQuery=new KunderaQuery();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  String mappedQuery=appMetadata.getQuery(jpaQuery);
  isNative=mappedQuery != null ? appMetadata.isNative(jpaQuery) : isNative;
  EntityMetadata m=null;
  if (!isNative) {
    KunderaQueryParser parser=new KunderaQueryParser(kunderaQuery,mappedQuery != null ? mappedQuery : jpaQuery);
    parser.parse();
    kunderaQuery.postParsingInit();
    m=kunderaQuery.getEntityMetadata();
  }
 else {
    kunderaQuery.isNativeQuery=true;
    m=KunderaMetadataManager.getEntityMetadata(mappedClass);
    Field entityClazzField=null;
    try {
      entityClazzField=kunderaQuery.getClass().getDeclaredField("String_Node_Str");
      if (entityClazzField != null && !entityClazzField.isAccessible()) {
        entityClazzField.setAccessible(true);
      }
      entityClazzField.set(kunderaQuery,mappedClass);
    }
 catch (    Exception e) {
      log.error(e.getMessage());
      throw new QueryHandlerException(e);
    }
  }
  Query query=null;
  try {
    query=getQuery(jpaQuery,persistenceDelegator,m,kunderaQuery);
  }
 catch (  Exception e) {
    log.error(e.getMessage());
    throw new QueryHandlerException(e);
  }
  return query;
}
Program: 176275
Project: 176275
Buggy source:
/** 
 * Gets the query instance.
 * @param jpaQuery the jpa query
 * @param persistenceDelegator the persistence delegator
 * @param persistenceUnits the persistence units
 * @return the query
 * @throws ClassNotFoundException the class not found exception
 * @throws SecurityException the security exception
 * @throws NoSuchMethodException the no such method exception
 * @throws IllegalArgumentException the illegal argument exception
 * @throws InstantiationException the instantiation exception
 * @throws IllegalAccessException the illegal access exception
 * @throws InvocationTargetException the invocation target exception
 */
private Query getQuery(String jpaQuery,PersistenceDelegator persistenceDelegator,EntityMetadata m) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
  Query query;
  Class clazz=persistenceDelegator.getClient(m).getQueryImplementor();
  @SuppressWarnings("String_Node_Str") Constructor constructor=clazz.getConstructor(String.class,KunderaQuery.class,PersistenceDelegator.class);
  query=(Query)constructor.newInstance(jpaQuery,kunderaQuery,persistenceDelegator);
  return query;
}

Fixed version (ground truth):
/** 
 * Gets the query instance.
 * @param jpaQuery the jpa query
 * @param persistenceDelegator the persistence delegator
 * @param persistenceUnits the persistence units
 * @return the query
 * @throws ClassNotFoundException the class not found exception
 * @throws SecurityException the security exception
 * @throws NoSuchMethodException the no such method exception
 * @throws IllegalArgumentException the illegal argument exception
 * @throws InstantiationException the instantiation exception
 * @throws IllegalAccessException the illegal access exception
 * @throws InvocationTargetException the invocation target exception
 */
private Query getQuery(String jpaQuery,PersistenceDelegator persistenceDelegator,EntityMetadata m,KunderaQuery kunderaQuery) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
  Query query;
  Class clazz=persistenceDelegator.getClient(m).getQueryImplementor();
  @SuppressWarnings("String_Node_Str") Constructor constructor=clazz.getConstructor(String.class,KunderaQuery.class,PersistenceDelegator.class);
  query=(Query)constructor.newInstance(jpaQuery,kunderaQuery,persistenceDelegator);
  return query;
}
Program: 176276
Project: 176276
Buggy source:
@Test public void testNativeQuery(){
  final String nativeQuery="String_Node_Str";
  Query query=em.createNativeQuery(nativeQuery,SampleEntity.class);
  Assert.assertNotNull(query);
  Assert.assertTrue(KunderaMetadata.INSTANCE.getApplicationMetadata().isNative(nativeQuery));
}

Fixed version (ground truth):
@Test public void testNativeQuery(){
  final String nativeQuery="String_Node_Str";
  Query query=em.createNativeQuery(nativeQuery,SampleEntity.class);
  Assert.assertNotNull(query);
}
Program: 176277
Project: 176277
Buggy source:
@Override protected List<Object> populateEntities(EntityMetadata m,Client client){
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  try {
    if (appMetadata.isNative(getJPAQuery())) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    BasicDBObject orderByClause=getOrderByClause();
    return ((MongoDBClient)client).loadData(m,createMongoQuery(m,getKunderaQuery().getFilterClauseQueue()),null,orderByClause,isSingleResult ? 1 : maxResult,getKeys(m,getKunderaQuery().getResult()),getKunderaQuery().getResult());
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new QueryHandlerException(e);
  }
}

Fixed version (ground truth):
@Override protected List<Object> populateEntities(EntityMetadata m,Client client){
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  try {
    String query=appMetadata.getQuery(getJPAQuery());
    boolean isNative=kunderaQuery.isNative();
    if (isNative) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    BasicDBObject orderByClause=getOrderByClause();
    return ((MongoDBClient)client).loadData(m,createMongoQuery(m,getKunderaQuery().getFilterClauseQueue()),null,orderByClause,isSingleResult ? 1 : maxResult,getKeys(m,getKunderaQuery().getResult()),getKunderaQuery().getResult());
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new QueryHandlerException(e);
  }
}
Program: 176278
Project: 176278
Buggy source:
@Override protected List<Object> recursivelyPopulateEntities(EntityMetadata m,Client client){
  List<EnhanceEntity> ls=new ArrayList<EnhanceEntity>();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  try {
    if (appMetadata.isNative(getJPAQuery())) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    BasicDBObject orderByClause=getOrderByClause();
    ls=((MongoDBClient)client).loadData(m,createMongoQuery(m,getKunderaQuery().getFilterClauseQueue()),m.getRelationNames(),orderByClause,isSingleResult ? 1 : maxResult,getKeys(m,getKunderaQuery().getResult()),getKunderaQuery().getResult());
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new QueryHandlerException(e);
  }
  return setRelationEntities(ls,client,m);
}

Fixed version (ground truth):
@Override protected List<Object> recursivelyPopulateEntities(EntityMetadata m,Client client){
  List<EnhanceEntity> ls=new ArrayList<EnhanceEntity>();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  try {
    String query=appMetadata.getQuery(getJPAQuery());
    boolean isNative=kunderaQuery.isNative();
    if (isNative) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    BasicDBObject orderByClause=getOrderByClause();
    ls=((MongoDBClient)client).loadData(m,createMongoQuery(m,getKunderaQuery().getFilterClauseQueue()),m.getRelationNames(),orderByClause,isSingleResult ? 1 : maxResult,getKeys(m,getKunderaQuery().getResult()),getKunderaQuery().getResult());
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new QueryHandlerException(e);
  }
  return setRelationEntities(ls,client,m);
}
Program: 176279
Project: 176279
Buggy source:
@Override protected List<Object> recursivelyPopulateEntities(EntityMetadata m,Client client){
  List<Object> entities=new ArrayList<Object>();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  if (appMetadata.isNative(getJPAQuery())) {
    String nativeQuery=appMetadata.getQuery(getJPAQuery());
    Neo4JNativeQuery nativeQueryImpl=Neo4JNativeQueryFactory.getNativeQueryImplementation(queryType);
    entities=nativeQueryImpl.executeNativeQuery(nativeQuery,(Neo4JClient)client,m);
  }
 else {
    String luceneQuery=getLuceneQuery(kunderaQuery);
    entities=((Neo4JClient)client).executeLuceneQuery(m,luceneQuery);
  }
  return setRelationEntities(entities,client,m);
}

Fixed version (ground truth):
@Override protected List<Object> recursivelyPopulateEntities(EntityMetadata m,Client client){
  List<Object> entities=new ArrayList<Object>();
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  String query=appMetadata.getQuery(getJPAQuery());
  boolean isNative=kunderaQuery.isNative();
  if (isNative) {
    String nativeQuery=query != null ? query : getJPAQuery();
    Neo4JNativeQuery nativeQueryImpl=Neo4JNativeQueryFactory.getNativeQueryImplementation(queryType);
    entities=nativeQueryImpl.executeNativeQuery(nativeQuery,(Neo4JClient)client,m);
  }
 else {
    String luceneQuery=getLuceneQuery(kunderaQuery);
    entities=((Neo4JClient)client).executeLuceneQuery(m,luceneQuery);
  }
  return setRelationEntities(entities,client,m);
}
Program: 176280
Project: 176280
Buggy source:
/** 
 * Checks whether a given JPA DML query is convertible to CQL
 * @param m
 * @return
 */
private boolean isQueryConvertibleToCQL(KunderaQuery kunderaQuery){
  EntityMetadata m=kunderaQuery.getEntityMetadata();
  if (kunderaQuery.isUpdateClause() && m.isCounterColumnType())   return false;
  List<String> opsNotAllowed=Arrays.asList(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"});
  boolean result=false;
  if (!kunderaQuery.getFilterClauseQueue().isEmpty()) {
    String idColumn=((AbstractAttribute)m.getIdAttribute()).getJPAColumnName();
    for (    Object o : kunderaQuery.getFilterClauseQueue()) {
      FilterClause filterClause=(FilterClause)o;
      if (!idColumn.equals(filterClause.getProperty()) || opsNotAllowed.contains(filterClause.getCondition())) {
        result=false;
        break;
      }
      result=true;
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Checks whether a given JPA DML query is convertible to CQL
 * @param m
 * @return
 */
private boolean isQueryConvertibleToCQL(KunderaQuery kunderaQuery){
  EntityMetadata m=kunderaQuery.getEntityMetadata();
  if (kunderaQuery.isUpdateClause() && m.isCounterColumnType())   return false;
  List<String> opsNotAllowed=Arrays.asList(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"});
  boolean result=false;
  if (!kunderaQuery.getFilterClauseQueue().isEmpty()) {
    String idColumn=((AbstractAttribute)m.getIdAttribute()).getJPAColumnName();
    for (    Object o : kunderaQuery.getFilterClauseQueue()) {
      if (o instanceof FilterClause) {
        FilterClause filterClause=(FilterClause)o;
        if (!idColumn.equals(filterClause.getProperty()) || opsNotAllowed.contains(filterClause.getCondition())) {
          result=false;
          break;
        }
        result=true;
      }
    }
  }
  return result;
}
Program: 176281
Project: 176281
Buggy source:
@Test public void testCallbackMethods(){
  Map<String,Object> props=new HashMap<String,Object>();
  props.put("String_Node_Str","String_Node_Str");
  EntityManagerFactory emf=Persistence.createEntityManagerFactory("String_Node_Str",props);
  EntityManager em=emf.createEntityManager();
  EntityMetadata m=KunderaMetadataManager.getEntityMetadata(PersonEventDispatch.class);
  Assert.assertNotNull(m.toString());
  PersonEventDispatch person=new PersonEventDispatch();
  person.setFirstName("String_Node_Str");
  person.setLastName("String_Node_Str");
  person.setPersonId("String_Node_Str");
  em.persist(person);
  em.clear();
  PersonEventDispatch result=em.find(PersonEventDispatch.class,"String_Node_Str");
  Assert.assertEquals(result.getLastName(),"String_Node_Str");
  onFindCallBack(em);
  em.close();
  emf.close();
}

Fixed version (ground truth):
@Test public void testCallbackMethods(){
  Map<String,Object> props=new HashMap<String,Object>();
  props.put("String_Node_Str","String_Node_Str");
  EntityManagerFactory emf=Persistence.createEntityManagerFactory("String_Node_Str",props);
  EntityManager em=emf.createEntityManager();
  EntityMetadata m=KunderaMetadataManager.getEntityMetadata(PersonEventDispatch.class);
  Assert.assertNotNull(m.toString());
  PersonEventDispatch person=new PersonEventDispatch();
  person.setFirstName("String_Node_Str");
  person.setLastName("String_Node_Str");
  person.setPersonId("String_Node_Str");
  em.persist(person);
  em.clear();
  PersonEventDispatch result=em.find(PersonEventDispatch.class,"String_Node_Str");
  Assert.assertEquals(result.getLastName(),"String_Node_Str");
  onFindCallBack(em);
  em.refresh(result);
  Assert.assertEquals(result.getLastName(),"String_Node_Str");
  em.close();
  emf.close();
}
Program: 176283
Project: 176283
Buggy source:
@Override public void find(){
  getCurrentNodeState().handleFind(this);
}

Fixed version (ground truth):
@Override public void find(){
  getCurrentNodeState().handleFind(this);
  EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(this.getDataClass());
  onPostEvent(metadata,EntityEvent.FIND);
}
Program: 176284
Project: 176284
Buggy source:
private final static Class getPostEvent(EntityEvent event){
  Class clazz=null;
switch (event) {
case PERSIST:
    clazz=PostPersist.class;
  break;
case UPDATE:
clazz=PostUpdate.class;
break;
case REMOVE:
clazz=PostRemove.class;
break;
default :
}
return clazz;
}

Fixed version (ground truth):
private final static Class getPostEvent(EntityEvent event){
  Class clazz=null;
switch (event) {
case PERSIST:
    clazz=PostPersist.class;
  break;
case UPDATE:
clazz=PostUpdate.class;
break;
case REMOVE:
clazz=PostRemove.class;
break;
case FIND:
clazz=PostLoad.class;
break;
default :
}
return clazz;
}
Program: 176285
Project: 176285
Buggy source:
@Override public void refresh(){
  getCurrentNodeState().handleRefresh(this);
}

Fixed version (ground truth):
@Override public void refresh(){
  getCurrentNodeState().handleRefresh(this);
  EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(this.getDataClass());
  onPostEvent(metadata,EntityEvent.FIND);
}
Program: 176286
Project: 176286
Buggy source:
@Override public List<?> getResultList(){
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + query);
  String q=luceneQuery;
  if (null == q) {
    q=getLuceneQueryFromJPAQuery();
  }
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + q);
  EntityMetadata m=kunderaQuery.getEntityMetadata();
  Client client=persistenceDelegeator.getClient(m);
  Map<String,Object> searchFilter=client.getIndexManager().search(m.getEntityClazz(),q,-1,maxResult);
  if (kunderaQuery.isAliasOnly()) {
    String[] primaryKeys=searchFilter.values().toArray(new String[]{});
    return persistenceDelegeator.find(m.getEntityClazz(),primaryKeys);
  }
 else {
    return persistenceDelegeator.find(m.getEntityClazz(),searchFilter);
  }
}

Fixed version (ground truth):
@Override public List<?> getResultList(){
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + query);
  String q=luceneQuery;
  if (null == q) {
    q=getLuceneQueryFromJPAQuery();
  }
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + q);
  EntityMetadata m=kunderaQuery.getEntityMetadata();
  Client client=persistenceDelegeator.getClient(m);
  handlePostEvent(m);
  Map<String,Object> searchFilter=client.getIndexManager().search(m.getEntityClazz(),q,-1,maxResult);
  if (kunderaQuery.isAliasOnly()) {
    String[] primaryKeys=searchFilter.values().toArray(new String[]{});
    return persistenceDelegeator.find(m.getEntityClazz(),primaryKeys);
  }
 else {
    return persistenceDelegeator.find(m.getEntityClazz(),searchFilter);
  }
}
Program: 176287
Project: 176287
Buggy source:
@Override public List<?> getResultList(){
  if (log.isDebugEnabled())   log.info("String_Node_Str" + query);
  List results=new ArrayList();
  EntityMetadata m=getEntityMetadata();
  Client client=persistenceDelegeator.getClient(m);
  if (!m.isRelationViaJoinTable() && (m.getRelationNames() == null || (m.getRelationNames().isEmpty()))) {
    results=populateEntities(m,client);
  }
 else {
    results=recursivelyPopulateEntities(m,client);
  }
  if (kunderaQuery.isDeleteUpdate()) {
    onDeleteOrUpdate(results);
  }
  if (results != null) {
    for (    Object obj : results) {
      KunderaMetadata.INSTANCE.getCoreMetadata().getLazyInitializerFactory().setProxyOwners(m,obj);
    }
  }
  return results != null ? results : new ArrayList();
}

Fixed version (ground truth):
@Override public List<?> getResultList(){
  if (log.isDebugEnabled())   log.info("String_Node_Str" + query);
  List results=new ArrayList();
  EntityMetadata m=getEntityMetadata();
  Client client=persistenceDelegeator.getClient(m);
  handlePostEvent(m);
  if (!m.isRelationViaJoinTable() && (m.getRelationNames() == null || (m.getRelationNames().isEmpty()))) {
    results=populateEntities(m,client);
  }
 else {
    results=recursivelyPopulateEntities(m,client);
  }
  if (kunderaQuery.isDeleteUpdate()) {
    onDeleteOrUpdate(results);
  }
  if (results != null) {
    for (    Object obj : results) {
      KunderaMetadata.INSTANCE.getCoreMetadata().getLazyInitializerFactory().setProxyOwners(m,obj);
    }
  }
  return results != null ? results : new ArrayList();
}
Program: 176288
Project: 176288
Buggy source:
@Test public void testCallbackMethods(){
  EntityManagerFactory emf=Persistence.createEntityManagerFactory("String_Node_Str");
  EntityManager em=emf.createEntityManager();
  EntityMetadata m=KunderaMetadataManager.getEntityMetadata(PersonEventDispatch.class);
  Assert.assertNotNull(m.toString());
  em.close();
  emf.close();
}

Fixed version (ground truth):
@Test public void testCallbackMethods(){
  Map<String,Object> props=new HashMap<String,Object>();
  props.put("String_Node_Str","String_Node_Str");
  EntityManagerFactory emf=Persistence.createEntityManagerFactory("String_Node_Str",props);
  EntityManager em=emf.createEntityManager();
  EntityMetadata m=KunderaMetadataManager.getEntityMetadata(PersonEventDispatch.class);
  Assert.assertNotNull(m.toString());
  PersonEventDispatch person=new PersonEventDispatch();
  person.setFirstName("String_Node_Str");
  person.setLastName("String_Node_Str");
  person.setPersonId("String_Node_Str");
  em.persist(person);
  em.clear();
  PersonEventDispatch result=em.find(PersonEventDispatch.class,"String_Node_Str");
  Assert.assertEquals(result.getLastName(),"String_Node_Str");
  onFindCallBack(em);
  em.close();
  emf.close();
}
Program: 176289
Project: 176289
Buggy source:
@PostLoad public void handledPostLoad(PersonEventDispatch user){
  user.setLastName("String_Node_Str");
}

Fixed version (ground truth):
@PostLoad public void handledPostLoad(PersonEventDispatch user){
  if (user != null) {
    user.setLastName("String_Node_Str");
  }
}
Program: 176291
Project: 176291
Buggy source:
/** 
 * Executes named native queries and returns response
 * @param headers
 * @param info
 * @return
 */
private Response executeNamedNativeQuery(HttpHeaders headers,UriInfo info){
  String entityClassName=info.getPathParameters().getFirst("String_Node_Str");
  String namedNativeQueryName=info.getPathParameters().getFirst("String_Node_Str");
  String sessionToken=headers.getRequestHeader(Constants.SESSION_TOKEN_HEADER_NAME).get(0);
  String mediaType=headers.getRequestHeader("String_Node_Str").get(0);
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + sessionToken + "String_Node_Str"+ entityClassName+ "String_Node_Str"+ namedNativeQueryName+ "String_Node_Str"+ mediaType);
  Class<?> entityClass=null;
  List result=null;
  try {
    EntityManager em=EMRepository.INSTANCE.getEM(sessionToken);
    entityClass=EntityUtils.getEntityClass(entityClassName,em);
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + entityClass);
    if (entityClass == null) {
      return Response.serverError().build();
    }
    Query q=em.createNamedQuery(namedNativeQueryName);
    result=q.getResultList();
  }
 catch (  Exception e) {
    log.error(e.getMessage());
    return Response.serverError().build();
  }
  if (result == null) {
    return Response.noContent().build();
  }
  String output=CollectionConverter.toString(result,entityClass,mediaType);
  return Response.ok(output).build();
}

Fixed version (ground truth):
/** 
 * Executes named native queries and returns response
 * @param headers
 * @param info
 * @return
 */
private Response executeNamedNativeQuery(HttpHeaders headers,UriInfo info){
  String entityClassName=info.getPathParameters().getFirst("String_Node_Str");
  String namedNativeQueryName=info.getPathParameters().getFirst("String_Node_Str");
  String sessionToken=headers.getRequestHeader(Constants.SESSION_TOKEN_HEADER_NAME).get(0);
  String mediaType=headers.getRequestHeader("String_Node_Str").get(0);
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + sessionToken + "String_Node_Str"+ entityClassName+ "String_Node_Str"+ namedNativeQueryName+ "String_Node_Str"+ mediaType);
  Class<?> entityClass=null;
  List result=null;
  try {
    EntityManager em=EMRepository.INSTANCE.getEM(sessionToken);
    entityClass=EntityUtils.getEntityClass(entityClassName,em);
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + entityClass);
    if (entityClass == null) {
      return Response.serverError().build();
    }
    Query q=em.createNamedQuery(namedNativeQueryName);
    result=q.getResultList();
  }
 catch (  Exception e) {
    log.error(e.getMessage(),e);
    return Response.serverError().build();
  }
  if (result == null) {
    return Response.noContent().build();
  }
  String output=CollectionConverter.toString(result,entityClass,mediaType);
  return Response.ok(output).build();
}
Program: 176292
Project: 176292
Buggy source:
/** 
 * Recursively fetches associated entities for a given <code>entity</code>
 * @param entity
 * @param relationsMap
 * @param client
 * @param m
 * @param pd
 * @return
 */
private Object handleAssociation(final Object entity,final Map<String,Object> relationsMap,final EntityMetadata m,final PersistenceDelegator pd,boolean lazilyloaded){
  for (  Relation relation : m.getRelations()) {
    ForeignKey relationType=relation.getType();
    Object relationalObject=PropertyAccessorHelper.getObject(entity,relation.getProperty());
    if (relationalObject == null || ProxyHelper.isProxyOrCollection(relationalObject)) {
      onRelation(entity,relationsMap,m,pd,relation,relationType,lazilyloaded);
    }
  }
  return entity;
}

Fixed version (ground truth):
/** 
 * Recursively fetches associated entities for a given <code>entity</code>
 * @param entity
 * @param relationsMap
 * @param client
 * @param m
 * @param pd
 * @return
 */
private Object handleAssociation(final Object entity,final Map<String,Object> relationsMap,final EntityMetadata m,final PersistenceDelegator pd,boolean lazilyloaded){
  for (  Relation relation : m.getRelations()) {
    ForeignKey relationType=relation.getType();
    Object relationalObject=PropertyAccessorHelper.getObject(entity,relation.getProperty());
    if (KunderaCoreUtils.isEmptyOrNull(relationalObject) || ProxyHelper.isProxyOrCollection(relationalObject)) {
      onRelation(entity,relationsMap,m,pd,relation,relationType,lazilyloaded);
    }
  }
  return entity;
}