1

次の HQL クエリがあります。

SELECT bu FROM Backup bu WHERE bu.status = :status ORDER BY bu.container.techId ASC

query > 0 の結果がある場合は常に、query.getResultList() が返されないことを意味します。しかし、ORDER BY 句を削除すると、SELECT bu FROM Backup bu WHERE bu.status = :status だけを残して正常に動作します。

私のクラスは次のとおりです。

public class Backup implements Serializable {

  @Id
    @Column(name="ID")
    @GenericGenerator(name = "generator", strategy = "guid", parameters = {})
    @GeneratedValue(generator = "generator")
    private String id;

    @Column(name="PVAID", nullable=true)
    private String PVAID;

    @Column(name="Error", nullable=true)
    private String error;

    @Column(name="\"Size\"", nullable=false)
    private Long backupSize;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="startdate", nullable=false)
    private Date startDate;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="enddate", nullable=true)
    private Date endDate;

    @Column(name="status", nullable=false)
    private Short status;

    @ManyToOne
    @JoinColumn(name="fullbackupid", referencedColumnName="ID", nullable=true)
    private Backup fullBackup;

    @ManyToOne
    @JoinColumn(name = "ContainerID", referencedColumnName="ID", nullable=false)
    private Container container;

}

public class Container implements Serializable {

   @Id
    @Column(name="ID")
    private String id;

    @ManyToOne
    @JoinColumn(name="HardwareNodeID", referencedColumnName="ID", nullable=false)
    private HardwareNode hardwareNode;

    @ManyToOne
    @JoinColumn(name="BackupServerID", referencedColumnName="ID", nullable=false)
    private BackupServer backupServer;

    @Column(name="TechID", nullable=false)
    private Integer techId;

    @Column(name="Exclude", nullable=false)
    private Boolean exclude;

    @Column(name="retry_backup", nullable=true)
    private Short retryBackUp;

    @Column(name="retry_delay", nullable=true)
    private Short retryDelay;

}

クエリを実行するコード

 public List<T> getAllByFilter(final boolean isNamedQuery, final String queryString, final HashMap<String, Object> fields, final int startRecord, final int maxResults) {
    logger.log(Level.INFO, "Loading all paginated");
    final EntityManager em = emf.createEntityManager();
    Query query = null;
    if(isNamedQuery) {
        query = em.createNamedQuery(queryString);
    } else {
        query = em.createQuery(queryString);
    }
    final Set<?> set = fields.entrySet();
    final Iterator<?> i = set.iterator();

    while(i.hasNext()){
      final Map.Entry me = (Map.Entry)i.next();
      final String field = (String)me.getKey();
      final Object value = me.getValue();
      System.out.println(me.getKey() + " : " + me.getValue() );
      query.setParameter(field, value);
    }
    query.setFirstResult(startRecord);
    if (maxResults!=0) query.setMaxResults(maxResults);
    return query.getResultList();
}

SQLクエリも問題ないようです:

13:45:03,583 INFO  [STDOUT] Hibernate: select top 41 backup0_.ID as ID153_, backup0_.IsFullBackup as IsFullBa2_153_, backup0_.PVAID as PVAID153_, backup0_.Error as Error153_, backup0_.[Size] as Size5_153_, backup0_.startdate as startdate153_, backup0_.enddate as enddate153_, backup0_.status as status153_, backup0_.ManualBackup as ManualBa9_153_, backup0_.fullbackupid as fullbac10_153_, backup0_.ContainerID as Contain11_153_ from Backups backup0_, Containers container1_ where backup0_.ContainerID=container1_.ID and backup0_.status=? order by container1_.TechID DESC

基盤となるデータベースは SQL Server です。

どこに問題があるのでしょうか? 誰も似たようなことに直面しましたか?ありがとう

4

0 に答える 0