我需要使用JPA更新字段。 我的连接池具有Derby服务器的所有设置。
我想更新所有帐户的余额。我在DAO中有这个方法。
public void addInterest(Account acc) {
// TODO Auto-generated method stub
int accBal = acc.getBalance();
accBal = accBal + 1000;
acc.setBalance(accBal);
}
我添加了
@PersistenceContext
private EntityManager em;
到dao类的顶部。
我的JSF调用支持bean中的方法 -
@EJB
private AccountAccessInterfaceLocal service;
public String adjust()
{
List<Account>accList = service.getAllAccounts();
try {
for (Account n : accList)
{
service.addInt(n);
}
return "success";
}
catch (Exception e)
{
return "failed";
}
}
其中service是我访问类的接口。
在我的访问类中,我有这个:
@EJB
private AccountDataAccessInteface dao;
public void addInt(Account acc) {
// TODO Auto-generated method stub
dao.addInterest(acc);
}
我似乎无法更新它。 我已经尝试过再次坚持,试图让它成为自己的实体经理。
我现在完全不知道。 任何帮助将不胜感激
编辑:我尝试的所有东西都得到了EJBTransactionRolledBackException