我正在从Oracle数据库中调用函数,并且遇到此异常:
org.hibernate.engine.query.ParameterRecognitionException:混合参数策略-仅使用命名,位置或JPA常规策略之一
这是我的 User.java 实体。
@Entity
@Table(name = "users", schema = "myschema")
@javax.persistence.NamedNativeQuery(name = "getPass", query = "{? call = his.get_abc(:mrno)}", resultClass = User.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
public class User {
@Id
@Column(name = "USERID", nullable = false)
private String userid;
@Column(name = "MRNO")
private String mrno;
private String username;
private String password;
private String fullName;
// Getters and Setters are written.
}
这就是我从Service类之一中调用此函数的方式。
public boolean validateUser(String mrno, String password) {
String completeMrno = utils.getMedicalRecordNumber(mrno);
EntityManagerFactory factory = Persistence.createEntityManagerFactory("his-dev");
EntityManager entityManager = factory.createEntityManager();
Query query = entityManager.createNamedQuery("getPass"); // <- this line is raising exception.
query.setParameter("mrno",completeMrno);
List<?> results = query.getResultList();
}
因此,要调用返回字符串的Oracle函数,需要进行哪些更改。
谢谢。让我知道是否需要更多信息。
答案 0 :(得分:0)
在下面的示例中找到如何使用JPA调用函数的方法:
Object result = entityManager.createNativeQuery("SELECT his.get_abc(:mrno) FROM DUAL")
.setParameter("mrno", completeMrno)
.getSingleResult();
String value = new String(result);