ObjectDB ObjectDB

TypedQuery implementation problems


Hi everyone, I'm having problems. I have implemented TypedQuery in a module of my web system and everything works perfectly.

but when making another module and implementing TypedQuery again it doesn't work anymore I would appreciate your opinion.

I leave a portion of my code with example.

public class AccountService {
     private EntityManager em;
     private AccountRepository accountRepository;
     public AccountService(EntityManager em, AccountRepository accountRepository) {
     this.em = em;
     this.accountRepository = accountRepository;
     public List<Account> getChartOfAccounts() {
     List<Account> retList = null;
     TypedQuery<Account> query = em.createQuery(
     "select new com.javatmp.module.accounting.entity.Account("
     + "acct.id, acct.accountCode, acct.name, acct.parentAccountId, "
     + "sum(case when att.amount > 0 then att.amount else 0 end),"
     + "sum(case when att.amount < 0 then (att.amount * -1) else 0 end), "
     + "sum(case when coalesce(att.amount, 0) > 0 then (abs(coalesce(att.amount, 0)) * coalesce(at.debitSign, 0)) "
     + "else (abs(coalesce(att.amount, 0)) * coalesce(at.creditSign, 0)) end), "
     + "acct.accountGroupId, acct.cashFlowId, ag.name, at.name, at.debitSign, at.creditSign, at.reportTypeId)"
     + " from Account acct"
     + " left outer join AccountTransaction att on acct.id = att.accountId"
     + " left outer join Transaction trans on att.transactionId = trans.id"
     + " left outer join AccountGroup ag on acct.accountGroupId = ag.id"
     + " left outer join AccountType at on at.id = ag.accountType"
     + " group by acct.id, acct.accountCode, acct.name, acct.parentAccountId, acct.accountGroupId,"
     + "acct.cashFlowId, ag.name, at.name, at.debitSign, at.creditSign, at.reportTypeId"
     + "", Account.class
     retList = query.getResultList();
     return retList;


The previous code worked very well now that I have tried to make a new module, it does not work, it indicates that the variables have not been declared. ex.

public class BudgetService {
     private EntityManager em;
     private BudgetRepository BudgetRepository;
     public BudgetService(EntityManager em, BudgetRepository budgetRepository) {
     this.em = em;
     this.budgetRepository = budgetRepository;
     public List<Budget> getBudgetPage() {
     List<Budget> retList = null;
     TypedQuery<Budget> query = em.createQuery(
     "select new com.javatmp.module.project.entity.Budget("
     + "budget.id, budget.budgetCode, budget.name, "//where the issues start, the variables are not defined
     + "", Budget.class
     retList = query.getResultList();
     return retList;



It may help if you include the exact error message in your post.

If the same code works in one application and doesn't work in another - check differences regarding the entity classes used and the database used.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)


To post on this website please sign in.