typedquery实现问题

3xiyfsfu  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(198)

大家好,我有点问题。我已经在我的web系统的一个模块中实现了typedquery,一切都很好。但是,当制作另一个模块并再次实现typedquery时,它不再起作用了,我将非常感谢您的意见。
我将代码的一部分留给示例。

@Service
    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;

}

前面的代码工作得很好,现在我已经尝试创建一个新模块,它不工作,它表明变量尚未声明。前任。

@Service
    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;

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题