混合参数策略-仅使用命名,位置或JPA常规策略之一 [英] Mixed parameter strategies - use just one of named, positional or JPA-ordinal strategy

查看:778
本文介绍了混合参数策略-仅使用命名,位置或JPA常规策略之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Oracle数据库中调用函数,并且遇到此异常:

I am calling function from Oracle database and facing this Exception:

org.hibernate.engine.query.ParameterRecognitionException:混合参数策略-仅使用命名,位置或JPA常规策略之一

org.hibernate.engine.query.ParameterRecognitionException: Mixed parameter strategies - use just one of named, positional or JPA-ordinal strategy

这是我的 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类之一中调用此函数的方式.

And this is how I am calling this function from my one of Service class.

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函数,需要进行哪些更改.

So, what changes are required in order to call Oracle Function which returns a String.

谢谢.让我知道是否需要更多信息.

Thanks. Let me know if more information is required.

推荐答案

在下面的示例中找到如何使用JPA调用函数的方法:

Find below an example how to call the function with JPA:

Object result = entityManager.createNativeQuery("SELECT his.get_abc(:mrno) FROM DUAL")
                                      .setParameter("mrno", completeMrno)
                                      .getSingleResult();
String value = new String(result);

这篇关于混合参数策略-仅使用命名,位置或JPA常规策略之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆