Dynamic Field Selection

//My Bean
@Entity
@Table(name= "ATUL")
public class AtulBean implements Serializable
{

	//ID, NAME, TELEPHONE
	@Id
	@Column(name="ID")
	private String id;
	
	@Column(name="NAME")
	private String name;
	
	@Column(name="TELEPHONE")
	private String telephone;
	
	@Column(name="ACCOUNT_STATUS") // Can Have values like : pending, confirmed, receieved
	private String accountStatus;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	
	public String getAccountStatus() {
		return accountStatus;
	}
	public void setAccountStatus(String accountStatus) {
		this.accountStatus = accountStatus;
	}


}
//My Search Criteria
public class AtulSearchCriteria extends AtulBean
{
	private boolean AND = true;
	private String[] orderBy; 
	private boolean[] desc; 
	private String[] groupBy;
	private String[] includeMask;
	
	private boolean isLikeName;
		
	public boolean isAND() {return AND;}
	public void setAND(boolean AND) {this.AND=AND;}
	
	public String[] getOrderBy() {return orderBy;}
	public void setOrderBy(String[] orderBy) { this.orderBy = orderBy;}
	
	public String[] getGroupBy() {return groupBy;}
	public void setGroupBy(String[] groupBy) {this.groupBy=groupBy; }
	
	public boolean[] isDesc() {return desc;}
	public void setDesc(boolean[] desc) { this.desc=desc; }
	
	public boolean isLikeName() {return isLikeName;}
	public void setIsLikeName(boolean isLikeName) {this.isLikeName=isLikeName;}
	
	
	public String[] getIncludeMask() {return includeMask;}
	public void setIncludeMask(String[] includeMask) { this.includeMask=includeMask;}
}
// My Dao
@Component
public class AtulDao 
{
	private final String ID = "id";
	private final NAME = "name";
	private final TELEPHONE = "telephone";
	private final ACCOUNT_STATUS = "accountStatus";
	
	EntityManagerFactory entityManagerFactory;
	
	private EntityManager entityManager;

    private CriteriaBuilder criteriaBuilder;

    private CriteriaQuery<AtulBean > criteriaQuery;

    private CriteriaUpdate<AtulBean > criteriaUpdate;

    private CriteriaDelete<AtulBean > criteriaDelete;

	
	public EntityManager getEntityManager()
    {
        if(this.entityManager==null)
            entityManager= entityManagerFactory.createEntityManager();

        return entityManager;
    }

    // Generic
    public CriteriaBuilder getCriteriaBuilder()
    {
        if(this.criteriaBuilder==null)
            criteriaBuilder= getEntityManager().getCriteriaBuilder();
        return criteriaBuilder;
    }

    // Generic
    @SuppressWarnings({"rawtypes","unchecked"})
    public CriteriaQuery<AtulBean > getCriteriaQuery(Class<AtulBean > bean)
    {
        if(this.criteriaQuery==null)
            criteriaQuery= getCriteriaBuilder().createQuery(bean);
        return criteriaQuery;
    }

    // Generic
    @SuppressWarnings({"rawtypes","unchecked"})
    public CriteriaUpdate getCriteriaUpdate(Class<AtulBean > bean)
    {
        if(this.criteriaUpdate==null)
            criteriaUpdate= getCriteriaBuilder().createCriteriaUpdate(bean);
        return criteriaUpdate;
    }

    // Generic
    @SuppressWarnings({"rawtypes","unchecked"})
    public CriteriaDelete<EmployeeBean> getCriteriaDelete(Class<EmployeeBean> bean)
    {
        if(this.criteriaDelete==null)
            criteriaDelete= getCriteriaBuilder().createCriteriaDelete(bean);
        return criteriaDelete;
    }
	
	//Finding On Basis Of Criteria	
	public List<AtulBean> findAtulBean(AtulSearchCriteria sc) throws Exception
	{
		List<Predicate> predicateList= SQLExpression(sc);
	

		 if(sc.isAND())
            predicate= criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
        else
            predicate= criteriaBuilder.or(predicateList.toArray(new Predicate[predicateList.size()]));

        if(sc.isDistinct())
            criteriaQuery.distinct(sc.isDistinct());
		
// How To Apply Include Mask Here
		
		TypedQuery<EmployeeBean> typedQuery= entityManager.createQuery(criteriaQuery);
        return typedQuery.getResultList();
	}
	
	
	public List<AtulBean> deleteAtulBean(AtulSearchCriteria sc) throws Exception
	{
		List<Predicate> predicateList= SQLExpression(sc);
		
		// This I know as below will work
		criteriaDelete.where(predicateList);
	}

	public void updateAtulBeanBulk(AtulBean bean, AtulSearchCriteria sc) throws Exception
	{
		CriteriaUpdate<AtulBean > criteriaUpdate= getCriteriaUpdate((Class<AtulBean>) bean.getClass());
        Root<AtulBean > root= criteriaUpdate.from((Class<AtulBean >) bean.getClass());

		
		//getValueToAssign(bean) I have not written this but it 
		//will invoke getter of field from bean using reflection
		if(sc.getIncludeMask()!=null)
			for(String fields : sc.getIncludeMask())
				criteriaUpdate.set(fields, getValueToAssign(bean, field));
				
		// This could be achieved by automatically since there must be mechanism by which above for loop 
		// can be avoided and mapping must be auto detected by ORM.
        
		List<Predicate> predicateList= SQLExpression(sc);
		
		// This I know as below will work
		criteriaUpdate.createQuery(predicateList).executeUpdate();
	}
	
	
	public List<Predicate> SQLExpression(AtulSearchCriteria sc)
    {
		List<Predicate> predicateLists = new ArrayList<Predicate>();
		if(!StringUtils.isBlank(sc.getId()))
			predicateLists.add(criteriaBuilder.equal(mappingBean.get(ID), sc.getId()));

		if(!StringUtils.isBlank(sc.getName()))
			predicateLists.add(criteriaBuilder.equal(mappingBean.get(NAME), sc.getName()));
		
		if(!StringUtils.isBlank(sc.getTelephone()))
			predicateLists.add(criteriaBuilder.equal(mappingBean.get(TELEPHONE), sc.getTelephone()));
		
		if(!StringUtils.isBlank(sc.getAccountStatus()) && sc.isLikeName)
			predicateLists.add(criteriaBuilder.like(mappingBean.<String>get(ACCOUNT_STATUS), "%"+sc.getAccountStatus()+"%"));
		
		return predicateLists;
	}
	
}
// This Class Is just for demonstration
public class Action 
{
	@Inject
	AtulDao dao;

	// Differrent methods arerepresentation of different business model scenarios where different data needed from
	// from same table
	// As of now I am considering simple selection
	
	private void searchAtulDetails1()
	{
		AtulSearchCriteria aSC =new  AtulSearchCriteria();
		aSC.setIncludeMask(new String[]{"name","status","id"});
		aSC.setName("At");
		aSC.setIsLikeName(true);
		
		 List<AtulBean> atulList = dao.findAtulBean(AtulSearchCriteria sc) 
	}
	
	private void searchAtulDetails2()
	{
		AtulSearchCriteria aSC =new  AtulSearchCriteria();
		aSC.setIncludeMask(new String[]{"name","id"});
		aSC.setName("At");
		aSC.setIsLikeName(true);
		
		 List<AtulBean> atulList = dao.findAtulBean(AtulSearchCriteria sc) 
	}

	private void searchAtulDetails3()
	{
		AtulSearchCriteria aSC =new  AtulSearchCriteria();
		aSC.setIncludeMask(new String[]{"telephone","id"});
		aSC.setName("At");
		aSC.setIsLikeName(true);
		aSC.setDesc(true);		
		List<AtulBean> atulList = dao.findAtulBean(AtulSearchCriteria sc) 
	}
	
}

Please ignore if any syntactical mistake

Above code is sample what I was talking about

here above codes if you check inside Action you will get what I need also

Hibernate & JPA talks about well designed db schema where every table maintains proper relation with its corresponding table like for eg Employee & Dept both have many to one scenario but what about where data base is not defined so properly structured and non of the table follow proper schema relations in that scenario we know how data relates but to wire them in proper relations is mammoth task for which organization don’t allow in such conditions how join solutions can help from hibernate no where its written

my point is real work challenges are missing in tutorials