我正在使用带有JPA的ADF作为模型我有一个页面,我正在使用按钮将一行添加到数据库中我的操作列表或调用函数
public void addAns() {
OperationBinding op1 =
BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("QuestionsFindByQid");
questions = (Questions) op1.getResult();
BigDecimal aid = maxAnsID();
Answer = new Answers();
Answer.setAnsvalue(AnsValue);
Answer.setUsers(user);
Answer.setQuestions(questions);
Answer.setGroups(questions.getGroups2());
Answer.setAnsdate(date);
Answer.setAid(aid);
// op =BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("Create");
//op.execute();
OperationBinding op = BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("persistAnswers");
op.getParamsMap().put("answers", Answer);
op.execute();
System.out.println(op.getResult());
op1 = BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("QuestionsFindByQid");
op1.execute();
FacesMessage message =
new FacesMessage("answer added succesfully ");
FacesContext.getCurrentInstance().addMessage(user.getUsername(), message);
}
我正在调用persistent方法进行插入我有一个表,其中我需要在插入时更新数据,我已经尝试重新执行绑定方法,但QuestionsFindByQid没有获得更新的数据我已经在持久化后检查了我的实体,我正在我的实体中获得更新的数据
有人能帮我吗
Krishna,您使用的是什么版本的JDev/ADF?
最简单的答案可能是,实现persistAnswers()
的任何类都不是隐式提交操作。persist()
调用本身更新JPA持久性上下文,但不更新DB。要应用更改,需要提交。
JDev提供了创建EJB会话bean或简单POJO的向导,POJO将充当处理事务的门面。这在最近的几个版本中得到了发展,最新的版本(12.1.3)为CRUD操作提供了通过JPA实体使用EJB和POJO外观的交钥匙解决方案。