nus-yam/ex-repair huggingface dataset:
Program: 176029
Project: 176029
Buggy source:
@Override public void persistJoinTable(JoinTableData joinTableData){
}

Fixed version (ground truth):
@Override public void persistJoinTable(JoinTableData joinTableData){
  String joinTableName=joinTableData.getJoinTableName();
  String invJoinColumnName=joinTableData.getInverseJoinColumnName();
  Map<Object,Set<Object>> joinTableRecords=joinTableData.getJoinTableRecords();
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(kunderaMetadata,joinTableData.getEntityClass());
  CQLTranslator translator=new CQLTranslator();
  String batch_Query=CQLTranslator.BATCH_QUERY;
  String insert_Query=translator.INSERT_QUERY;
  StringBuilder builder=new StringBuilder();
  builder.append(CQLTranslator.DEFAULT_KEY_NAME);
  builder.append(CQLTranslator.COMMA_STR);
  builder.append(translator.ensureCase(new StringBuilder(),joinTableData.getJoinColumnName(),false));
  builder.append(CQLTranslator.COMMA_STR);
  builder.append(translator.ensureCase(new StringBuilder(),joinTableData.getInverseJoinColumnName(),false));
  insert_Query=StringUtils.replace(insert_Query,CQLTranslator.COLUMN_FAMILY,translator.ensureCase(new StringBuilder(),joinTableName,false).toString());
  insert_Query=StringUtils.replace(insert_Query,CQLTranslator.COLUMNS,builder.toString());
  StringBuilder columnValueBuilder=new StringBuilder();
  StringBuilder statements=new StringBuilder();
  for (  Object key : joinTableRecords.keySet()) {
    PropertyAccessor accessor=PropertyAccessorFactory.getPropertyAccessor((Field)entityMetadata.getIdAttribute().getJavaMember());
    Set<Object> values=joinTableRecords.get(key);
    for (    Object value : values) {
      if (value != null) {
        String insertQuery=insert_Query;
        columnValueBuilder.append(CQLTranslator.QUOTE_STR);
        columnValueBuilder.append(PropertyAccessorHelper.getString(key) + "String_Node_Str" + PropertyAccessorHelper.getString(value));
        columnValueBuilder.append(CQLTranslator.QUOTE_STR);
        columnValueBuilder.append(CQLTranslator.COMMA_STR);
        translator.appendValue(columnValueBuilder,key.getClass(),key,true,false);
        columnValueBuilder.append(CQLTranslator.COMMA_STR);
        translator.appendValue(columnValueBuilder,value.getClass(),value,true,false);
        insertQuery=StringUtils.replace(insertQuery,CQLTranslator.COLUMN_VALUES,columnValueBuilder.toString());
        statements.append(insertQuery);
        statements.append("String_Node_Str");
      }
    }
  }
  if (!StringUtils.isBlank(statements.toString())) {
    batch_Query=StringUtils.replace(batch_Query,CQLTranslator.STATEMENT,statements.toString());
    StringBuilder batchBuilder=new StringBuilder();
    batchBuilder.append(batch_Query);
    batchBuilder.append(CQLTranslator.APPLY_BATCH);
    execute(batchBuilder.toString(),null);
  }
}
Program: 176031
Project: 176031
Buggy source:
/** 
 * check for Tables method check the existence of schema and table.
 * @param tableInfos list of TableInfos and ksDef object of KsDef
 * @param ksDef the ks def
 * @throws TException
 * @throws InvalidRequestException
 */
private void onValidateTables(List<TableInfo> tableInfos,KsDef ksDef) throws Exception {
  cassandra_client.set_keyspace(ksDef.getName());
  for (  TableInfo tableInfo : tableInfos) {
    onValidateTable(ksDef,tableInfo);
  }
}

Fixed version (ground truth):
/** 
 * check for Tables method check the existence of schema and table.
 * @param tableInfos list of TableInfos and ksDef object of KsDef
 * @param ksDef the ks def
 * @throws TException
 * @throws InvalidRequestException
 */
private void onValidateTables(List<TableInfo> tableInfos,KsDef ksDef) throws Exception {
  cassandra_client.set_keyspace(ksDef.getName());
  for (  TableInfo tableInfo : tableInfos) {
    if (isCql3Enabled(tableInfo) && !tableInfo.getType().equals(Type.SUPER_COLUMN_FAMILY.name())) {
      CqlMetadata metadata=new CqlMetadata();
      Map<ByteBuffer,String> name_types=new HashMap<ByteBuffer,String>();
      Map<ByteBuffer,String> value_types=new HashMap<ByteBuffer,String>();
      List<ColumnInfo> columnInfos=tableInfo.getColumnMetadatas();
      name_types.put(ByteBufferUtil.bytes(tableInfo.getIdColumnName()),"String_Node_Str");
      value_types.put(ByteBufferUtil.bytes(tableInfo.getIdColumnName()),CassandraValidationClassMapper.getValidationClassInstance(tableInfo.getTableIdType(),true).getName());
      for (      ColumnInfo info : columnInfos) {
        name_types.put(ByteBufferUtil.bytes(info.getColumnName()),"String_Node_Str");
        value_types.put(ByteBufferUtil.bytes(info.getColumnName()),CassandraValidationClassMapper.getValidationClassInstance(info.getType(),true).getName());
      }
      metadata.setDefault_name_type("String_Node_Str");
      metadata.setDefault_value_type("String_Node_Str");
      metadata.setName_types(name_types);
      metadata.setValue_types(value_types);
      CQLTranslator translator=new CQLTranslator();
      final String describeTable="String_Node_Str";
      StringBuilder builder=new StringBuilder(describeTable);
      translator.ensureCase(builder,tableInfo.getTableName(),false);
      cassandra_client.set_cql_version(CassandraConstants.CQL_VERSION_3_0);
      CqlResult cqlResult=cassandra_client.execute_cql3_query(ByteBufferUtil.bytes(builder.toString()),Compression.NONE,ConsistencyLevel.ONE);
      CqlMetadata originalMetadata=cqlResult.getSchema();
      int compareResult=originalMetadata.compareTo(metadata);
      if (compareResult > 0) {
        onLog(tableInfo,metadata,value_types,originalMetadata);
        throw new SchemaGenerationException("String_Node_Str");
      }
    }
 else {
      onValidateTable(ksDef,tableInfo);
    }
  }
}
Program: 176032
Project: 176032
Buggy source:
private void onValidateTable(KsDef ksDef,TableInfo tableInfo) throws Exception {
  boolean tablefound=false;
  for (  CfDef cfDef : ksDef.getCf_defs()) {
    if (cfDef.getName().equals(tableInfo.getTableName()) && (cfDef.getColumn_type().equals(ColumnFamilyType.getInstanceOf(tableInfo.getType()).name()))) {
      if (cfDef.getColumn_type().equals(ColumnFamilyType.Standard.name())) {
        for (        ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) {
          onValidateColumn(tableInfo,cfDef,columnInfo);
        }
        tablefound=true;
        break;
      }
 else       if (cfDef.getColumn_type().equals(ColumnFamilyType.Super.name())) {
        tablefound=true;
      }
    }
  }
  if (!tablefound) {
    throw new SchemaGenerationException("String_Node_Str" + tableInfo.getTableName() + "String_Node_Str"+ databaseName+ "String_Node_Str","String_Node_Str",databaseName,tableInfo.getTableName());
  }
}

Fixed version (ground truth):
/** 
 * @param ksDef
 * @param tableInfo
 * @throws Exception
 */
private void onValidateTable(KsDef ksDef,TableInfo tableInfo) throws Exception {
  boolean tablefound=false;
  for (  CfDef cfDef : ksDef.getCf_defs()) {
    if (cfDef.getName().equals(tableInfo.getTableName()) && (cfDef.getColumn_type().equals(ColumnFamilyType.getInstanceOf(tableInfo.getType()).name()))) {
      if (cfDef.getColumn_type().equals(ColumnFamilyType.Standard.name())) {
        for (        ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) {
          onValidateColumn(tableInfo,cfDef,columnInfo);
        }
        tablefound=true;
        break;
      }
 else       if (cfDef.getColumn_type().equals(ColumnFamilyType.Super.name())) {
        tablefound=true;
      }
    }
  }
  if (!tablefound) {
    throw new SchemaGenerationException("String_Node_Str" + tableInfo.getTableName() + "String_Node_Str"+ databaseName+ "String_Node_Str","String_Node_Str",databaseName,tableInfo.getTableName());
  }
}
Program: 176034
Project: 176034
Buggy source:
/** 
 * Gets the entity manager factory.
 * @return the entity manager factory
 */
private EntityManagerFactoryImpl getEntityManagerFactory(){
  EntityManagerFactory emf=Persistence.createEntityManagerFactory(_PU);
  return (EntityManagerFactoryImpl)emf;
}

Fixed version (ground truth):
/** 
 * Gets the entity manager factory.
 * @return the entity manager factory
 */
private EntityManagerFactoryImpl getEntityManagerFactory(Map propertyMap,final String persistenceUnit){
  EntityManagerFactory emf=Persistence.createEntityManagerFactory(persistenceUnit,propertyMap);
  return (EntityManagerFactoryImpl)emf;
}
Program: 176035
Project: 176035
Buggy source:
/** 
 * Returns collection of column values for given join table. TODO: Method is very much tightly coupled with Join table implementation and does not serve purpose as it is meant for.
 */
@Override public <E>List<E> getColumnsById(String schemaName,String tableName,String pKeyColumnName,String columnName,Object pKeyColumnValue,Class columnJavaType){
  Object connection=null;
  List results=new ArrayList();
  try {
    connection=getConnection();
    String valueAsStr=PropertyAccessorHelper.getString(pKeyColumnValue);
    Double score=getDouble(valueAsStr);
    Set<String> resultKeys=null;
    if (resource != null && resource.isActive()) {
      Response response=((Transaction)connection).zrangeByScore(getHashKey(tableName,valueAsStr),score,score);
      ((Transaction)connection).exec();
      resultKeys=(Set<String>)response.get();
    }
 else {
      resultKeys=((Jedis)connection).zrangeByScore(getHashKey(tableName,valueAsStr),score,score);
    }
    results=fetchColumn(columnName,connection,results,resultKeys);
    return results;
  }
  finally {
    onCleanup(connection);
  }
}

Fixed version (ground truth):
/** 
 * Returns collection of column values for given join table. TODO: Method is very much tightly coupled with Join table implementation and does not serve purpose as it is meant for.
 */
@Override public <E>List<E> getColumnsById(String schemaName,String tableName,String pKeyColumnName,String columnName,Object pKeyColumnValue,Class columnJavaType){
  Object connection=null;
  List results=new ArrayList();
  try {
    connection=getConnection();
    String valueAsStr=PropertyAccessorHelper.getString(pKeyColumnValue);
    Double score=getDouble(valueAsStr);
    Set<String> resultKeys=null;
    if (resource != null && resource.isActive()) {
      Response response=((Transaction)connection).zrangeByScore(getHashKey(tableName,valueAsStr),score,score);
      ((RedisTransaction)resource).onExecute(((Transaction)connection));
      resultKeys=(Set<String>)response.get();
    }
 else {
      resultKeys=((Jedis)connection).zrangeByScore(getHashKey(tableName,valueAsStr),score,score);
    }
    results=fetchColumn(columnName,connection,results,resultKeys);
    return results;
  }
  finally {
    onCleanup(connection);
  }
}
Program: 176036
Project: 176036
Buggy source:
private Object[] findIdsByColumn(String tableName,String columnName,Object columnValue){
  Object connection=null;
  try {
    connection=getConnection();
    String valueAsStr=PropertyAccessorHelper.getString(columnValue);
    Set<String> results=null;
    if (resource != null && resource.isActive()) {
      Response response=((Transaction)connection).zrangeByScore(getHashKey(tableName,columnName),getDouble(valueAsStr),getDouble(valueAsStr));
      ((Transaction)connection).exec();
      results=(Set<String>)response.get();
    }
 else {
      results=((Jedis)connection).zrangeByScore(getHashKey(tableName,columnName),getDouble(valueAsStr),getDouble(valueAsStr));
    }
    if (results != null) {
      return results.toArray(new Object[0]);
    }
  }
  finally {
    onCleanup(connection);
  }
  return null;
}

Fixed version (ground truth):
private Object[] findIdsByColumn(String tableName,String columnName,Object columnValue){
  Object connection=null;
  try {
    connection=getConnection();
    String valueAsStr=PropertyAccessorHelper.getString(columnValue);
    Set<String> results=null;
    if (resource != null && resource.isActive()) {
      Response response=((Transaction)connection).zrangeByScore(getHashKey(tableName,columnName),getDouble(valueAsStr),getDouble(valueAsStr));
      ((RedisTransaction)resource).onExecute(((Transaction)connection));
      results=(Set<String>)response.get();
    }
 else {
      results=((Jedis)connection).zrangeByScore(getHashKey(tableName,columnName),getDouble(valueAsStr),getDouble(valueAsStr));
    }
    if (results != null) {
      return results.toArray(new Object[0]);
    }
  }
  finally {
    onCleanup(connection);
  }
  return null;
}
Program: 176038
Project: 176038
Buggy source:
/** 
 * @param columnName
 * @param connection
 * @param results
 * @param resultKeys
 */
private List fetchColumn(String columnName,Object connection,List results,Set<String> resultKeys){
  for (  String hashKey : resultKeys) {
    List columnValues=null;
    if (resource != null && resource.isActive()) {
      Response response=((Transaction)connection).hmget(hashKey,columnName);
      ((Transaction)connection).exec();
      columnValues=(List)response.get();
    }
 else {
      columnValues=((Jedis)connection).hmget(hashKey,columnName);
    }
    if (columnValues != null && !columnValues.isEmpty()) {
      results.addAll(columnValues);
    }
  }
  return results;
}

Fixed version (ground truth):
/** 
 * @param columnName
 * @param connection
 * @param results
 * @param resultKeys
 */
private List fetchColumn(String columnName,Object connection,List results,Set<String> resultKeys){
  for (  String hashKey : resultKeys) {
    List columnValues=null;
    if (resource != null && resource.isActive()) {
      Response response=((Transaction)connection).hmget(hashKey,columnName);
      ((RedisTransaction)resource).onExecute(((Transaction)connection));
      columnValues=(List)response.get();
    }
 else {
      columnValues=((Jedis)connection).hmget(hashKey,columnName);
    }
    if (columnValues != null && !columnValues.isEmpty()) {
      results.addAll(columnValues);
    }
  }
  return results;
}
Program: 176041
Project: 176041
Buggy source:
Transaction bindResource(Jedis resource){
  Transaction tx=null;
  if (resources.isEmpty()) {
    tx=resource.multi();
    resources.add(tx);
  }
 else {
    tx=resources.get(0);
  }
  return tx;
}

Fixed version (ground truth):
Transaction bindResource(Jedis resource){
  Transaction tx=null;
  tx=resource.multi();
  resources.add(tx);
  return tx;
}
Program: 176042
Project: 176042
Buggy source:
@Override protected void onPersist(EntityMetadata metadata,Object entity,Object id,List<RelationHolder> relationHolders){
  boolean proxyRemoved=removeKunderaProxies(metadata,entity,relationHolders);
  Transaction tx=null;
  s=getStatelessSession();
  tx=s.beginTransaction();
  try {
    if (!isUpdate) {
      id=s.insert(entity);
      updateForeignKeys(metadata,id,relationHolders);
      tx.commit();
    }
 else {
      s.update(entity);
      if (proxyRemoved) {
        updateForeignKeys(metadata,id,relationHolders);
      }
      tx.commit();
    }
  }
 catch (  org.hibernate.exception.ConstraintViolationException e) {
    s.update(entity);
    log.info(e.getMessage());
    tx.commit();
  }
catch (  HibernateException e) {
    log.error("String_Node_Str",metadata.getEntityClazz(),e);
    throw new PersistenceException(e);
  }
}

Fixed version (ground truth):
@Override protected void onPersist(EntityMetadata metadata,Object entity,Object id,List<RelationHolder> relationHolders){
  boolean proxyRemoved=removeKunderaProxies(metadata,entity,relationHolders);
  Transaction tx=null;
  s=getStatelessSession();
  tx=s.beginTransaction();
  try {
    if (!isUpdate) {
      id=s.insert(entity);
      updateForeignKeys(metadata,id,relationHolders);
      tx.commit();
    }
 else {
      s.update(entity);
      if (proxyRemoved) {
        updateForeignKeys(metadata,id,relationHolders);
      }
      tx.commit();
    }
  }
 catch (  org.hibernate.exception.ConstraintViolationException e) {
    s.update(entity);
    log.info(e.getMessage());
    tx.commit();
  }
catch (  HibernateException e) {
    log.error("String_Node_Str",metadata.getEntityClazz(),e);
    e.printStackTrace();
    throw new PersistenceException(e);
  }
}
Program: 176043
Project: 176043
Buggy source:
/** 
 * Find.
 * @param query the native fquery
 * @param relations the relations
 * @param m the m
 * @return the list
 */
public int onExecuteUpdate(String query,Map<Parameter,Object> parameterMap){
  s=getStatelessSession();
  Query q=s.createQuery(query);
  setParameters(parameterMap,q);
  Transaction tx=s.beginTransaction();
  int i=q.executeUpdate();
  tx.commit();
  return i;
}

Fixed version (ground truth):
/** 
 * Find.
 * @param query the native fquery
 * @param relations the relations
 * @param m the m
 * @return the list
 */
public int onExecuteUpdate(String query,Map<Parameter,Object> parameterMap){
  s=getStatelessSession();
  Query q=s.createQuery(query);
  setParameters(parameterMap,q);
  System.out.println(query);
  Transaction tx=s.beginTransaction();
  int i=q.executeUpdate();
  tx.commit();
  return i;
}
Program: 176044
Project: 176044
Buggy source:
public void deleteByColumn(String schemaName,String tableName,String columnName,Object columnValue){
  StringBuffer query=new StringBuffer();
  query.append("String_Node_Str").append(getFromClause(schemaName,tableName)).append("String_Node_Str").append(columnName).append("String_Node_Str").append("String_Node_Str").append(columnValue).append("String_Node_Str");
  onExecuteUpdate(query.toString(),null);
}

Fixed version (ground truth):
public void deleteByColumn(String schemaName,String tableName,String columnName,Object columnValue){
  StringBuffer query=new StringBuffer();
  query.append("String_Node_Str").append(getFromClause(schemaName,tableName)).append("String_Node_Str").append(columnName).append("String_Node_Str").append("String_Node_Str").append(columnValue).append("String_Node_Str");
  StatelessSession s=getStatelessSession();
  Transaction tx=s.beginTransaction();
  onNativeUpdate(query.toString(),null);
  tx.commit();
}
Program: 176045
Project: 176045
Buggy source:
/** 
 * Updates foreign keys into master table
 * @param metadata
 * @param id
 * @param relationHolders
 */
private void updateForeignKeys(EntityMetadata metadata,Object id,List<RelationHolder> relationHolders){
  for (  RelationHolder rh : relationHolders) {
    String linkName=rh.getRelationName();
    Object linkValue=rh.getRelationValue();
    if (linkName != null && linkValue != null) {
      String clause=getFromClause(metadata.getSchema(),metadata.getTableName());
      String updateSql="String_Node_Str" + clause + "String_Node_Str"+ linkName+ "String_Node_Str"+ linkValue+ "String_Node_Str"+ ((AbstractAttribute)metadata.getIdAttribute()).getJPAColumnName()+ "String_Node_Str"+ id+ "String_Node_Str";
      onExecuteUpdate(updateSql,null);
    }
  }
}

Fixed version (ground truth):
/** 
 * Updates foreign keys into master table
 * @param metadata
 * @param id
 * @param relationHolders
 */
private void updateForeignKeys(EntityMetadata metadata,Object id,List<RelationHolder> relationHolders){
  for (  RelationHolder rh : relationHolders) {
    String linkName=rh.getRelationName();
    Object linkValue=rh.getRelationValue();
    if (linkName != null && linkValue != null) {
      String clause=getFromClause(metadata.getSchema(),metadata.getTableName());
      String updateSql="String_Node_Str" + clause + "String_Node_Str"+ linkName+ "String_Node_Str"+ linkValue+ "String_Node_Str"+ ((AbstractAttribute)metadata.getIdAttribute()).getJPAColumnName()+ "String_Node_Str"+ id+ "String_Node_Str";
      onNativeUpdate(updateSql,null);
    }
  }
}
Program: 176046
Project: 176046
Buggy source:
/** 
 * Instantiates a new entity manager impl.
 * @param factory the factory
 */
EntityManagerImpl(EntityManagerFactory factory,PersistenceUnitTransactionType transactionType,PersistenceContextType persistenceContextType){
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + getPersistenceUnit());
  }
  this.persistenceCache=new PersistenceCache((Cache)factory.getCache());
  this.persistenceCache.setPersistenceContextType(persistenceContextType);
  this.factory=factory;
  this.persistenceContextType=persistenceContextType;
  this.transactionType=transactionType;
  this.persistenceCache=new PersistenceCache();
  this.persistenceCache.setPersistenceContextType(persistenceContextType);
  this.persistenceDelegator=new PersistenceDelegator(((EntityManagerFactoryImpl)this.factory).getKunderaMetadataInstance(),this.persistenceCache);
  for (  String pu : ((EntityManagerFactoryImpl)this.factory).getPersistenceUnits()) {
    this.persistenceDelegator.loadClient(pu,discoverClient(pu));
  }
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + getPersistenceUnit());
  }
}

Fixed version (ground truth):
/** 
 * Instantiates a new entity manager impl.
 * @param factory the factory
 */
EntityManagerImpl(EntityManagerFactory factory,PersistenceUnitTransactionType transactionType,PersistenceContextType persistenceContextType){
  this.factory=factory;
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + getPersistenceUnit());
  }
  this.persistenceCache=new PersistenceCache((Cache)factory.getCache());
  this.persistenceCache.setPersistenceContextType(persistenceContextType);
  this.persistenceContextType=persistenceContextType;
  this.transactionType=transactionType;
  this.persistenceCache=new PersistenceCache();
  this.persistenceCache.setPersistenceContextType(persistenceContextType);
  this.persistenceDelegator=new PersistenceDelegator(((EntityManagerFactoryImpl)this.factory).getKunderaMetadataInstance(),this.persistenceCache);
  for (  String pu : ((EntityManagerFactoryImpl)this.factory).getPersistenceUnits()) {
    this.persistenceDelegator.loadClient(pu,discoverClient(pu));
  }
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + getPersistenceUnit());
  }
}
Program: 176047
Project: 176047
Buggy source:
@Override public Enum fromString(Class targetClass,String string){
  if (targetClass != null && string != null) {
    try {
      return Enum.valueOf(targetClass,string.trim().toUpperCase());
    }
 catch (    IllegalArgumentException ex) {
      log.error("String_Node_Str",ex);
      throw new PropertyAccessException(ex);
    }
  }
  return null;
}

Fixed version (ground truth):
@Override public Enum fromString(Class targetClass,String string){
  if (targetClass != null && string != null) {
    try {
      return Enum.valueOf(targetClass,string.trim());
    }
 catch (    IllegalArgumentException ex) {
      log.error("String_Node_Str",ex);
      throw new PropertyAccessException(ex);
    }
  }
  return null;
}
Program: 176049
Project: 176049
Buggy source:
private void processGeneratedValueAnnotation(Class<?> clazz,String persistenceUnit,EntityMetadata m,Map<String,IdDiscriptor> entityNameToKeyDiscriptorMap){
  GeneratedValueProcessor processer=new GeneratedValueProcessor();
  String pu=m.getPersistenceUnit();
  String clientFactoryName=KunderaMetadataManager.getPersistenceUnitMetadata(kunderaMetadata,m.getPersistenceUnit()).getClient();
  if (pu != null && pu.equals(persistenceUnit) || clientFactoryName.equalsIgnoreCase("String_Node_Str")) {
    Field f=(Field)m.getIdAttribute().getJavaMember();
    if (f.isAnnotationPresent(GeneratedValue.class)) {
      processer.process(clazz,f,m,entityNameToKeyDiscriptorMap);
    }
  }
}

Fixed version (ground truth):
private void processGeneratedValueAnnotation(Class<?> clazz,String persistenceUnit,EntityMetadata m,Map<String,IdDiscriptor> entityNameToKeyDiscriptorMap){
  GeneratedValueProcessor processer=new GeneratedValueProcessor();
  String pu=m.getPersistenceUnit();
  String clientFactoryName=getClientFactoryName(persistenceUnit);
  if (pu != null && pu.equals(persistenceUnit) || clientFactoryName.equalsIgnoreCase("String_Node_Str")) {
    Field f=(Field)m.getIdAttribute().getJavaMember();
    if (f.isAnnotationPresent(GeneratedValue.class)) {
      processer.process(clazz,f,m,entityNameToKeyDiscriptorMap);
    }
  }
}
Program: 176051
Project: 176051
Buggy source:
private Object generateId(Object e,EntityMetadata m,Client<?> client,final KunderaMetadata kunderaMetadata){
  Metamodel metamodel=KunderaMetadataManager.getMetamodel(kunderaMetadata,m.getPersistenceUnit());
  IdDiscriptor keyValue=((MetamodelImpl)metamodel).getKeyValue(e.getClass().getName());
  if (keyValue != null) {
    String clientFactoryName=KunderaMetadataManager.getPersistenceUnitMetadata(kunderaMetadata,m.getPersistenceUnit()).getClient();
    if (clientFactoryName != null && !clientFactoryName.equalsIgnoreCase("String_Node_Str")) {
      if (client != null) {
        GenerationType type=keyValue.getStrategy();
switch (type) {
case TABLE:
          return onTableGenerator(m,client,keyValue,e);
case SEQUENCE:
        return onSequenceGenerator(m,client,keyValue,e);
case AUTO:
      return onAutoGenerator(m,client,e);
case IDENTITY:
    throw new UnsupportedOperationException(GenerationType.class.getSimpleName() + "String_Node_Str" + type+ "String_Node_Str"+ client.getClass().getName());
}
}
}
 else {
int hashCode=e.hashCode();
Object generatedId=PropertyAccessorHelper.fromSourceToTargetClass(m.getIdAttribute().getJavaType(),Integer.class,new Integer(hashCode));
PropertyAccessorHelper.setId(e,m,generatedId);
return generatedId;
}
}
return null;
}

Fixed version (ground truth):
private Object generateId(Object e,EntityMetadata m,Client<?> client,final KunderaMetadata kunderaMetadata){
  Metamodel metamodel=KunderaMetadataManager.getMetamodel(kunderaMetadata,m.getPersistenceUnit());
  IdDiscriptor keyValue=((MetamodelImpl)metamodel).getKeyValue(e.getClass().getName());
  if (keyValue != null) {
    if (!client.getQueryImplementor().getSimpleName().equalsIgnoreCase("String_Node_Str")) {
      if (client != null) {
        GenerationType type=keyValue.getStrategy();
switch (type) {
case TABLE:
          return onTableGenerator(m,client,keyValue,e);
case SEQUENCE:
        return onSequenceGenerator(m,client,keyValue,e);
case AUTO:
      return onAutoGenerator(m,client,e);
case IDENTITY:
    throw new UnsupportedOperationException(GenerationType.class.getSimpleName() + "String_Node_Str" + type+ "String_Node_Str"+ client.getClass().getName());
}
}
}
 else {
int hashCode=e.hashCode();
Object generatedId=PropertyAccessorHelper.fromSourceToTargetClass(m.getIdAttribute().getJavaType(),Integer.class,new Integer(hashCode));
PropertyAccessorHelper.setId(e,m,generatedId);
return generatedId;
}
}
return null;
}
Program: 176052
Project: 176052
Buggy source:
/** 
 * parse and process non unary relations {e.g. 1-M and M-M}
 * @return  true, if is a non unary relation and processed.
 */
private boolean onNonUnaryRelation(){
  if (!relation.isUnary()) {
    if (Collection.class.isAssignableFrom(target.getClass())) {
      Collection childrenObjects=(Collection)target;
      for (      Object childObj : childrenObjects) {
        if (childObj != null) {
          this.generator.onBuildChildNode(childObj,metadata,this.pd,pc,source,relation);
        }
      }
    }
 else     if (Map.class.isAssignableFrom(target.getClass())) {
      Map childrenObjects=(Map)target;
      if (childrenObjects != null && !ProxyHelper.isProxyCollection(childrenObjects)) {
        for (        Map.Entry entry : (Set<Map.Entry>)childrenObjects.entrySet()) {
          Object relObject=entry.getKey();
          Object entityObject=entry.getValue();
          Node childNode=this.generator.generate(entityObject,pd,pc);
          if (childNode != null) {
            if (StringUtils.isEmpty(relation.getMappedBy()) && relation.getProperty().getAnnotation(MapKeyJoinColumn.class) != null) {
              NodeLink nodeLink=new NodeLink(source.getNodeId(),childNode.getNodeId());
              this.generator.setLink(source,relation,childNode,nodeLink);
              nodeLink.addLinkProperty(LinkProperty.LINK_VALUE,relObject);
            }
          }
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * parse and process non unary relations {e.g. 1-M and M-M}
 * @return  true, if is a non unary relation and processed.
 */
private boolean onNonUnaryRelation(){
  if (!relation.isUnary()) {
    if (Collection.class.isAssignableFrom(target.getClass())) {
      Collection childrenObjects=(Collection)target;
      for (      Object childObj : childrenObjects) {
        if (childObj != null) {
          this.generator.onBuildChildNode(childObj,metadata,this.pd,pc,source,relation);
        }
      }
    }
 else     if (Map.class.isAssignableFrom(target.getClass())) {
      Map childrenObjects=(Map)target;
      if (childrenObjects != null && !ProxyHelper.isProxyCollection(childrenObjects)) {
        for (        Map.Entry entry : (Set<Map.Entry>)childrenObjects.entrySet()) {
          Object relObject=entry.getKey();
          Object entityObject=entry.getValue();
          Node childNode=this.generator.generate(entityObject,pd,pc,null);
          if (childNode != null) {
            if (StringUtils.isEmpty(relation.getMappedBy()) && relation.getProperty().getAnnotation(MapKeyJoinColumn.class) != null) {
              NodeLink nodeLink=new NodeLink(source.getNodeId(),childNode.getNodeId());
              this.generator.setLink(source,relation,childNode,nodeLink);
              nodeLink.addLinkProperty(LinkProperty.LINK_VALUE,relObject);
            }
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 176053
Project: 176053
Buggy source:
/** 
 * Build node. Check for: 1. Node state, whether in pc or not 2. Node dirty check
 * @param entity      originating entity
 * @param pc          persistence cache.
 * @param entityId    entity id
 * @param nodeId      node id.
 * @return            node builder instance.
 */
private NodeBuilder buildNode(Object entity,PersistenceCache pc,Object entityId,String nodeId){
  Node nodeInPersistenceCache=pc.getMainCache().getNodeFromCache(nodeId);
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,entity,((Field)entityMetadata.getIdAttribute().getJavaMember()).isAnnotationPresent(EmbeddedId.class) ? new ManagedState() : new TransientState(),pc,entityId);
  }
 else {
    node=nodeInPersistenceCache;
    node.setPersistenceCache(pc);
    node.setTraversed(false);
  }
  onDirtyCheck(entity,node);
  node.setData(entity);
  return this;
}

Fixed version (ground truth):
/** 
 * Build node. Check for: 1. Node state, whether in pc or not 2. Node dirty check
 * @param entity      originating entity
 * @param pc          persistence cache.
 * @param entityId    entity id
 * @param nodeId      node id.
 * @return            node builder instance.
 */
private NodeBuilder buildNode(Object entity,PersistenceCache pc,Object entityId,String nodeId){
  Node nodeInPersistenceCache=pc.getMainCache().getNodeFromCache(nodeId);
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
  if (nodeInPersistenceCache == null) {
    this.state=state != null ? this.state : new TransientState();
    node=new Node(nodeId,entity,((Field)entityMetadata.getIdAttribute().getJavaMember()).isAnnotationPresent(EmbeddedId.class) ? new ManagedState() : this.state,pc,entityId);
  }
 else {
    node=nodeInPersistenceCache;
    node.setPersistenceCache(pc);
    node.setTraversed(false);
  }
  onDirtyCheck(entity,node);
  node.setData(entity);
  return this;
}
Program: 176054
Project: 176054
Buggy source:
/** 
 * Set link property
 * @param node       node
 * @param relation   relation
 * @param childNode  target node
 * @param nodeLink   node link(bridge)
 */
void setLink(Node node,Relation relation,Node childNode,NodeLink nodeLink){
  nodeLink.setMultiplicity(relation.getType());
  EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(node.getDataClass());
  nodeLink.setLinkProperties(getLinkProperties(metadata,relation));
  childNode.addParentNode(nodeLink,node);
  node.addChildNode(nodeLink,childNode);
}

Fixed version (ground truth):
/** 
 * Set link property
 * @param node node
 * @param relation relation
 * @param childNode target node
 * @param nodeLink node link(bridge)
 */
void setLink(Node node,Relation relation,Node childNode,NodeLink nodeLink){
  nodeLink.setMultiplicity(relation.getType());
  EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(node.getDataClass());
  nodeLink.setLinkProperties(getLinkProperties(metadata,relation));
  childNode.addParentNode(nodeLink,node);
  node.addChildNode(nodeLink,childNode);
}
Program: 176055
Project: 176055
Buggy source:
/** 
 * Generate entity graph and returns after assigning headnode. n
 * @param entity    entity.
 * @param delegator delegator
 * @param pc        persistence cache
 * @return          object graph.
 */
public <E>ObjectGraph generateGraph(E entity,PersistenceDelegator delegator){
  this.builder.assign(this);
  Node node=generate(entity,delegator,delegator.getPersistenceCache());
  this.builder.assignHeadNode(node);
  return this.builder.getGraph();
}

Fixed version (ground truth):
/** 
 * Generate entity graph and returns after assigning headnode. n
 * @param entity entity.
 * @param delegator delegator
 * @param pc persistence cache
 * @return object graph.
 */
public <E>ObjectGraph generateGraph(E entity,PersistenceDelegator delegator,NodeState state){
  this.builder.assign(this);
  Node node=generate(entity,delegator,delegator.getPersistenceCache(),state);
  this.builder.assignHeadNode(node);
  return this.builder.getGraph();
}
Program: 176056
Project: 176056
Buggy source:
/** 
 * On assigning node link properties
 * @param node       node
 * @param relation   relation
 * @param childNode  child node
 */
private void assignNodeLinkProperty(Node node,Relation relation,Node childNode){
  NodeLink nodeLink=new NodeLink(node.getNodeId(),childNode.getNodeId());
  setLink(node,relation,childNode,nodeLink);
}

Fixed version (ground truth):
/** 
 * On assigning node link properties
 * @param node node
 * @param relation relation
 * @param childNode child node
 */
private void assignNodeLinkProperty(Node node,Relation relation,Node childNode){
  NodeLink nodeLink=new NodeLink(node.getNodeId(),childNode.getNodeId());
  setLink(node,relation,childNode,nodeLink);
}
Program: 176057
Project: 176057
Buggy source:
/** 
 * On pre checks before generating graph. performed checks: <li> Check if entity is valid. </li> <li> generated and set id in case   {@link GeneratedValue} is present and not set.</li><li> Check if primary key is not null.</li>
 * @param entity  entity
 * @param client  client
 * @return        entity id
 */
private <E>Object onPreChecks(E entity,Client client){
  Object id=null;
  if (!new NullOrInvalidEntityRule<E>().validate(entity)) {
    EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
    id=PropertyAccessorHelper.getId(entity,entityMetadata);
    if (ObjectGraphUtils.onAutoGenerateId((Field)entityMetadata.getIdAttribute().getJavaMember(),id)) {
      id=new IdGenerator().generateAndSetId(entity,entityMetadata,client);
    }
    new PrimaryKeyNullCheck<Object>().validate(id);
  }
  return id;
}

Fixed version (ground truth):
/** 
 * On pre checks before generating graph. performed checks: <li>Check if entity is valid.</li> <li>generated and set id in case  {@link GeneratedValue} is present and not set.</li> <li>Check if primarykey is not null.</li>
 * @param entity entity
 * @param client client
 * @return entity id
 */
private <E>Object onPreChecks(E entity,PersistenceDelegator delegator){
  Object id=null;
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
  id=PropertyAccessorHelper.getId(entity,entityMetadata);
  if (ObjectGraphUtils.onAutoGenerateId((Field)entityMetadata.getIdAttribute().getJavaMember(),id)) {
    id=new IdGenerator().generateAndSetId(entity,entityMetadata,delegator.getClient(entityMetadata));
  }
  new PrimaryKeyNullCheck<Object>().validate(id);
  return id;
}
Program: 176058
Project: 176058
Buggy source:
/** 
 * Generate graph for head node.  <li> traverse through it's relational entities recursively
 * @param entity     entity object
 * @param delegator  delegator object
 * @param pc         persistence cache
 * @return           head node
 */
<E>Node generate(E entity,PersistenceDelegator delegator,PersistenceCache pc){
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
  Object entityId=onPreChecks(entity,delegator.getClient(entityMetadata));
  Node node=builder.buildNode(entity,pc,entityId);
  if (node != null && !traversedNodes.contains(node)) {
    for (    Relation relation : entityMetadata.getRelations()) {
      Object childObject=PropertyAccessorHelper.getObject(entity,relation.getProperty());
      if (childObject != null && !ProxyHelper.isProxyOrCollection(childObject)) {
        EntityMetadata childMetadata=KunderaMetadataManager.getEntityMetadata(PropertyAccessorHelper.getGenericClass(relation.getProperty()));
        childObject=onIfSharedByPK(relation,childObject,childMetadata,entityId);
        node=builder.getRelationBuilder(childObject,relation,node).assignResources(delegator,pc,childMetadata).build().getNode();
      }
    }
    traversedNodes.add(node);
  }
  return node;
}

Fixed version (ground truth):
/** 
 * Generate graph for head node. <li>traverse through it's relational entities recursively
 * @param entity entity object
 * @param delegator delegator object
 * @param pc persistence cache
 * @return head node
 */
<E>Node generate(E entity,PersistenceDelegator delegator,PersistenceCache pc,NodeState state){
  if (!new NullOrInvalidEntityRule<E>().validate(entity)) {
    Object entityId=onPreChecks(entity,delegator);
    Node node=builder.buildNode(entity,pc,entityId,state);
    node=traverseNode(entity,delegator,pc,entityId,node);
    return node;
  }
  return null;
}
Program: 176059
Project: 176059
Buggy source:
/** 
 * Check and set if relation is set via primary key.
 * @param relation        relation
 * @param childObject     target entity
 * @param childMetadata   target entity metadata
 * @param entityId        entity id
 * @return                target entity.  
 */
private Object onIfSharedByPK(Relation relation,Object childObject,EntityMetadata childMetadata,Object entityId){
  if (relation.isJoinedByPrimaryKey()) {
    PropertyAccessorHelper.setId(childObject,childMetadata,entityId);
  }
  return childObject;
}

Fixed version (ground truth):
/** 
 * Check and set if relation is set via primary key.
 * @param relation relation
 * @param childObject target entity
 * @param childMetadata target entity metadata
 * @param entityId entity id
 * @return target entity.
 */
private Object onIfSharedByPK(Relation relation,Object childObject,EntityMetadata childMetadata,Object entityId){
  if (relation.isJoinedByPrimaryKey()) {
    PropertyAccessorHelper.setId(childObject,childMetadata,entityId);
  }
  return childObject;
}
Program: 176060
Project: 176060
Buggy source:
/** 
 * On building child node
 * @param childObject    child object
 * @param childMetadata  child metadata
 * @param delegator      persistence delegator
 * @param pc             persistence cache
 * @param node           node
 * @param relation       entity relation
 */
void onBuildChildNode(Object childObject,EntityMetadata childMetadata,PersistenceDelegator delegator,PersistenceCache pc,Node node,Relation relation){
  Node childNode=generate(childObject,delegator,pc);
  if (childNode != null) {
    assignNodeLinkProperty(node,relation,childNode);
  }
}

Fixed version (ground truth):
/** 
 * On building child node
 * @param childObject child object
 * @param childMetadata child metadata
 * @param delegator persistence delegator
 * @param pc persistence cache
 * @param node node
 * @param relation entity relation
 */
void onBuildChildNode(Object childObject,EntityMetadata childMetadata,PersistenceDelegator delegator,PersistenceCache pc,Node node,Relation relation){
  Node childNode=generate(childObject,delegator,pc,null);
  if (childNode != null) {
    assignNodeLinkProperty(node,relation,childNode);
  }
}
Program: 176062
Project: 176062
Buggy source:
/** 
 * Removes an entity object from persistence cache.
 */
public void remove(Object e){
  if (e == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  EntityMetadata metadata=getMetadata(e.getClass());
  ObjectGraph graph=new GraphGenerator().generateGraph(e,this);
  Node node=graph.getHeadNode();
  try {
    lock.writeLock().lock();
    node.setPersistenceDelegator(this);
    node.remove();
    flushManager.buildFlushStack(node,EventType.DELETE);
    flush();
  }
  finally {
    lock.writeLock().unlock();
  }
  graph.clear();
  graph=null;
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + e.getClass());
}

Fixed version (ground truth):
/** 
 * Removes an entity object from persistence cache.
 */
public void remove(Object e){
  if (e == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  EntityMetadata metadata=getMetadata(e.getClass());
  ObjectGraph graph=new GraphGenerator().generateGraph(e,this,new ManagedState());
  Node node=graph.getHeadNode();
  try {
    lock.writeLock().lock();
    node.setPersistenceDelegator(this);
    node.remove();
    flushManager.buildFlushStack(node,EventType.DELETE);
    flush();
  }
  finally {
    lock.writeLock().unlock();
  }
  graph.clear();
  graph=null;
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + e.getClass());
}
Program: 176063
Project: 176063
Buggy source:
@Test public void testRelation(){
  List<SocialProfile> profiles=new ArrayList<SocialProfile>();
  FacebookProfile fbprofile=new FacebookProfile();
  fbprofile.setId(103l);
  fbprofile.setFacebookId("String_Node_Str");
  fbprofile.setFacebookUser("String_Node_Str");
  fbprofile.setuserType("String_Node_Str");
  profiles.add(fbprofile);
  TwitterProfile twprofile1=new TwitterProfile();
  twprofile1.setTwitterId("String_Node_Str");
  twprofile1.setTwitterName("String_Node_Str");
  twprofile1.setId(102l);
  profiles.add(twprofile1);
  twprofile1.setuserType("String_Node_Str");
  UserAccount uacc=new UserAccount();
  uacc.setId(101l);
  uacc.setDispName("String_Node_Str");
  uacc.setSocialProfiles(profiles);
  twprofile1.setuserAccount(uacc);
  fbprofile.setuserAccount(uacc);
  em.getTransaction().begin();
  em.persist(uacc);
  em.getTransaction().commit();
  objCache.add(uacc);
  objCache.add(twprofile1);
  objCache.add(fbprofile);
  em.clear();
  String uaQuery="String_Node_Str";
  Query q=em.createQuery(uaQuery);
  List<UserAccount> results=q.getResultList();
  Assert.assertEquals(1,results.size());
  Assert.assertEquals("String_Node_Str",results.get(0).getDispName());
  Assert.assertEquals(2,results.get(0).getSocialProfiles().size());
  em.clear();
  em.remove(results.get(0));
}

Fixed version (ground truth):
@Test public void testRelation(){
  List<SocialProfile> profiles=new ArrayList<SocialProfile>();
  FacebookProfile fbprofile=new FacebookProfile();
  fbprofile.setId(103l);
  fbprofile.setFacebookId("String_Node_Str");
  fbprofile.setFacebookUser("String_Node_Str");
  fbprofile.setuserType("String_Node_Str");
  profiles.add(fbprofile);
  TwitterProfile twprofile1=new TwitterProfile();
  twprofile1.setTwitterId("String_Node_Str");
  twprofile1.setTwitterName("String_Node_Str");
  twprofile1.setId(102l);
  profiles.add(twprofile1);
  twprofile1.setuserType("String_Node_Str");
  UserAccount uacc=new UserAccount();
  uacc.setId(101l);
  uacc.setDispName("String_Node_Str");
  uacc.setSocialProfiles(profiles);
  twprofile1.setuserAccount(uacc);
  fbprofile.setuserAccount(uacc);
  em.getTransaction().begin();
  em.persist(uacc);
  em.getTransaction().commit();
  objCache.add(uacc);
  objCache.add(twprofile1);
  objCache.add(fbprofile);
  em.clear();
  String uaQuery="String_Node_Str";
  Query q=em.createQuery(uaQuery);
  List<UserAccount> results=q.getResultList();
  Assert.assertEquals(1,results.size());
  Assert.assertEquals("String_Node_Str",results.get(0).getDispName());
  Assert.assertEquals(2,results.get(0).getSocialProfiles().size());
  em.remove(results.get(0));
  em.clear();
}
Program: 176064
Project: 176064
Buggy source:
/** 
 * Creates the query.
 * @param jpaQuery the jpa query
 * @return the query
 */
Query createQuery(String jpaQuery){
  return getQueryInstance(jpaQuery,false,null);
}

Fixed version (ground truth):
/** 
 * Creates the query.
 * @param jpaQuery the jpa query
 * @return the query
 */
Query createQuery(String jpaQuery,final String persistenceUnit){
  Query query=new QueryResolver().getQueryImplementation(jpaQuery,getClient(persistenceUnit).getQueryImplementor(),this);
  return query;
}
Program: 176065
Project: 176065
Buggy source:
/** 
 * Gets the client.
 * @param m the m
 * @return the client
 */
public Client getClient(EntityMetadata m){
  if (m == null) {
    throw new KunderaException("String_Node_Str");
  }
  String persistenceUnit=m.getPersistenceUnit();
  Client client=clientMap.get(persistenceUnit);
  if (client == null) {
    throw new ClientResolverException("String_Node_Str" + persistenceUnit);
  }
  return client;
}

Fixed version (ground truth):
private Client getClient(final String persistenceUnit){
  Client client=clientMap.get(persistenceUnit);
  if (client == null) {
    throw new ClientResolverException("String_Node_Str" + persistenceUnit);
  }
  return client;
}
Program: 176066
Project: 176066
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,Class mappedClass,boolean isNative){
  if (jpaQuery == null) {
    throw new QueryHandlerException("String_Node_Str");
  }
  KunderaQuery kunderaQuery=null;
  ApplicationMetadata appMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata();
  String mappedQuery=appMetadata.getQuery(jpaQuery);
  isNative=mappedQuery != null ? appMetadata.isNative(jpaQuery) : isNative;
  EntityMetadata m=null;
  if (!isNative) {
    kunderaQuery=new KunderaQuery(mappedQuery != null ? mappedQuery : jpaQuery);
    KunderaQueryParser parser=new KunderaQueryParser(kunderaQuery);
    parser.parse();
    kunderaQuery.postParsingInit();
    m=kunderaQuery.getEntityMetadata();
  }
 else {
    if (appMetadata.isNative(jpaQuery)) {
      mappedClass=appMetadata.getMappedClass(jpaQuery);
    }
    kunderaQuery=new KunderaQuery(jpaQuery);
    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;
}

Fixed version (ground truth):
public Query getQueryImplementation(String jpaQuery,Class queryClazz,final PersistenceDelegator persistenceDelegator){
  KunderaQuery kunderaQuery=new KunderaQuery(jpaQuery);
  kunderaQuery.isNativeQuery=true;
  Query query=null;
  try {
    Constructor constructor=queryClazz.getConstructor(KunderaQuery.class,PersistenceDelegator.class);
    query=(Query)constructor.newInstance(kunderaQuery,persistenceDelegator);
  }
 catch (  Exception e) {
    log.error(e.getMessage());
    throw new QueryHandlerException(e);
  }
  return query;
}