1 回答

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
經(jīng)過(guò)幾個(gè)小時(shí)的嘗試,我找到了一種讓它工作的方法。
首先我添加@NamedStoredProcedureQuery到我的CompanyResource實(shí)體類(lèi):
CompanyResource.java
@Entity
@Table(name = "company_resource")
@NamedStoredProcedureQueries({
@NamedStoredProcedureQuery(name = "getAllMetalFromCompaniesByPlayerId",
procedureName = "getAllMetalFromCompaniesByPlayerId",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "playerId", type = Integer.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "metalSum", type = BigDecimal.class)
})
})
@IdClass(CompanyResourcePK.class)
public class CompanyResource {
...
}
然后我改變了我的getMetalResourceByPlayerId()方法CompanyResourceServiceImpl如下:
CompanyResourceServiceImpl.java
@Service
public class CompanyResourceServiceImpl implements CompanyResourceService {
@PersistenceContext
private EntityManager entityManager;
...
private int getMetalResourceByPlayerId(int theId) {
StoredProcedureQuery theQuery = entityManager.createNamedStoredProcedureQuery("getAllMetalFromCompaniesByPlayerId");
theQuery.setParameter("Param1", theId);
BigDecimal outAmount = (BigDecimal) theQuery.getSingleResult();
return outAmount.intValue();
}
...
}
添加回答
舉報(bào)