我可以使用NamedNativeQuery动态添加参数吗?

问题描述

我想使用NamednativeQuery从列表中添加多个参数(大小是动态的)。这是我的实体:

@Entity
@Table(name = "SEND_REQUESTS")

@NamednativeQuery(name = "SendRequest.insertByStudyIdWorkstationId",query = "insert into send_requests (study_id,image_id,workstation_id) "
                                + "select series.study_id,:workstationId "
                                + "from series series,images images "
                                + "where series.study_id=:studyId and images.series_id = series.series_id "
                                + "and NOT EXISTS (select * from send_requests sr2 "
                                + "   where sr2.study_id=:studyId and sr2.image_id = images.image_id "
                                + "   and sr2.workstation_id = :workstationId)")
public class SendRequest implements Serializable { ...

这是我现在使用查询的方式:

 @Override
    public Integer addOrUpdateSendRequest(Long workstationId,Long studyId) {
        Query query = getSession().getNamednativeQuery("SendRequest.insertByStudyIdWorkstationId");
        query.setParameter(STUDY_ID,studyId,LongType.INSTANCE);
        query.setParameter(WORKSTATION_ID,workstationId,LongType.INSTANCE);
        query.executeUpdate();

在这里,我将像这样添加一个名为List<Long> seriesIds的参数:

@Override
    public Integer addOrUpdateSendRequest(Long workstationId,Long studyId,*List<Long> seriesIds*) {
        ...

并更改查询,如下所示:

query = "insert into send_requests (study_id,images images "
                                + "where series.study_id=:studyId and images.series_id = series.series_id "
                              * + "where series.series_id=:seriesId or series.series_id=seriesId *
                                + "and NOT EXISTS (select * from send_requests sr2 "
                                + "   where sr2.study_id=:studyId and sr2.image_id = images.image_id "
                                + "   and sr2.workstation_id = :workstationId)")

seriesId的数量是动态的,我很好奇这是否可以在不多次调用同一查询的情况下实现。如果无法使用NamednativeQuery,最好的方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)