1 回答
TA贡献1826条经验 获得超6个赞
经过几个小时的尝试,我找到了一种让它工作的方法。
首先我添加@NamedStoredProcedureQuery到我的CompanyResource实体类:
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();
}
...
}
添加回答
举报