Postgresql JPA在使用Postgres处理存储过程时找不到参数
在以下问题上所做的任何努力都是非常值得注意的。 我正在尝试使用@NamedStoredProcedureQueries调用存储过程 下面是我的实体类的代码片段Postgresql JPA在使用Postgres处理存储过程时找不到参数,postgresql,jpa,stored-procedures,entitymanager,Postgresql,Jpa,Stored Procedures,Entitymanager,在以下问题上所做的任何努力都是非常值得注意的。 我正在尝试使用@NamedStoredProcedureQueries调用存储过程 下面是我的实体类的代码片段 @Entity @Table(name = "tx_oppertunity") @NamedStoredProcedureQueries({ // @NamedStoredProcedureQuery(name = "oppertunity.pastOppertunities", procedureName = "pastOppertu
@Entity
@Table(name = "tx_oppertunity")
@NamedStoredProcedureQueries({ //
@NamedStoredProcedureQuery(name = "oppertunity.pastOppertunities", procedureName = "pastOppertunities",resultSetMappings="myMapping")})
@SqlResultSetMappings({
@SqlResultSetMapping(
name = "myMapping",
classes = @ConstructorResult(targetClass = DataHolder.class, columns = { @ColumnResult(name = "oppertunityid") }))
})
public class Oppertunity {
/** The oppertunity id. */
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GEN_TX_OPPERTUNITY_SEQ")
@SequenceGenerator(allocationSize = 1, name = "GEN_TX_OPPERTUNITY_SEQ", sequenceName = "tx_oppertunity_seq")
@Column(name = "oppertunity_id", nullable = false, unique = true)
private Long oppertunity_id;
// other fields to follow
}
我的存储过程是用postgres编写的,如下所示
CREATE OR REPLACE FUNCTION pastOppertunities()
RETURNS TABLE(oppertunityid integer) AS
$BODY$
BEGIN
RETURN QUERY select cast((opp.oppertunity_id) as integer) from tx_oppertunity opp where (opp.end_date)< (NOW() - INTERVAL '2 days');
END;
$BODY$
LANGUAGE plpgsql
public class DataHolder implements Serializable{
private Integer oppertunityid;
/**
* @return the oppertunityid
*/
public Integer getOppertunityid() {
return oppertunityid;
}
/**
* @param oppertunityid the oppertunityid to set
*/
public void setOppertunityid(Integer oppertunityid) {
this.oppertunityid = oppertunityid;
}
public DataHolder(Integer oppertunityid) {
this.oppertunityid = oppertunityid;
}
}
但是,如果我尝试使用JPA存储库运行该过程
@Procedure(name = "oppertunity.pastOppertunities")
public List<DataHolder> findPastOppertunities();
我不确定我在这里缺少什么,所有参数都在@SQLREsultSetMapping中正确指定,我在过程中添加了显式类型转换以强制返回整数值
有一篇帖子建议使用实体管理器调用存储过程,经过长时间的斗争后,我使用实体管理器进行了调用,它非常有效
public List<DataHolder> findPastOppertunities() {
// TODO Auto-generated method stub
StoredProcedureQuery spq = em.createStoredProcedureQuery("pastOppertunities");
List<DataHolder> resultList = spq.getResultList();
return resultList;
//return oppRepo.findPastOppertunities();
}
public List findpastoppertonities(){
//TODO自动生成的方法存根
StoredProcedurey spq=em.createStoredProcedurey(“PastOpportunities”);
List resultList=spq.getResultList();
返回结果列表;
//返回oppRepo.findpastopertunities();
}
然而,我想了解,如果JPA存储库存在缺陷,为什么JPA不能使用@SqlResultSetMapping映射strored过程的结果
谢谢,
迪佩什
public List<DataHolder> findPastOppertunities() {
// TODO Auto-generated method stub
StoredProcedureQuery spq = em.createStoredProcedureQuery("pastOppertunities");
List<DataHolder> resultList = spq.getResultList();
return resultList;
//return oppRepo.findPastOppertunities();
}