我正在尝试在一个老式的spring应用程序中从hibernate4.3.1.final迁移到5.4.27.final(大多数spring组件都在版本4.3.13.final上)。更新版本修复了几个小问题(类导入)并使用maven构建应用程序后,在尝试在tomcat 7.0.107上部署此web应用程序时出现以下错误(堆栈跟踪的一部分指向根异常):
2121 Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List hr.chus.plus.dao.repository.StatusUpdateRepository .findAlarmLogsByZoneAndDatesAndNeedsAck(java.lang.Integer,java.lang.String,java.util.Date,java.util.Date)!
-- cut --
2150 Caused by: org.hibernate.QueryException: Could not resolve identifier `acks` as plural-attribute [FROM hr.chus.plus.dao.model.jpa.StatusUpdate WHERE updateType='ALARM' AND relatedId=:alarmId AND subtype='ZONE' AND subtypeUuid=:zone AND timestamp BETWEEN :start AND :end AND needAck=true AND size(acks)=0]
2151 at org.hibernate.QueryException.generateQueryException(QueryException.java:120) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2152 at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2153 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2154 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2155 at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2156 at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2157 at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2158 at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2159 at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
2160 ... 79 common frames omitted
2161 Caused by: org.hibernate.QueryException: Could not resolve identifier `acks` as plural-attribute
2162 at org.hibernate.hql.internal.ast.tree.CollectionPathNode.from(CollectionPathNode.java:123) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
这个jpql与以前的版本运行和部署得很好。
上述实体的相关部分如下:
报警日志:
@Entity
@Table(name = "z_alarm_log")
@SecondaryTable(name = "z_alarm_log_data", pkJoinColumns = { @PrimaryKeyJoinColumn(name = "id") })
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class AlarmLog extends AbstractLogEntity {
private static final int SUBTYPE_MAX_LENGTH = 10;
@Column(name = "alarm_id")
private Integer alarmId;
@Column(name = "trouble", columnDefinition = "TINYINT")
private Boolean trouble;
@Lob
@Basic(fetch = FetchType.EAGER)
@Column(name = "data", columnDefinition = "BLOB", table = "z_alarm_log_data")
private String data;
@Column(name = "need_ack", columnDefinition = "TINYINT")
private Boolean needAck = false;
@OneToMany(mappedBy = "log", fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
private Set<AlarmLogAck> acks = new HashSet<>();
@Column(name = "code", nullable = false)
private int code = 0;
@Column(name = "subtype", length = SUBTYPE_MAX_LENGTH)
private String subtype;
@Column(name = "subtype_id")
private Integer subtypeId;
@Column(name = "subtype_uuid", nullable = true, columnDefinition = "CHAR")
private String subtypeUuid;
报警确认:
@Entity
@Table(name = "z_alarm_log_ack")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AlarmLogAck extends AbstractLongIdEntity {
private static final int MESSAGE_MAX_LENGTH = 200;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "zipato_id")
private Zipato zipato;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "log_id")
private AlarmLog log;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id")
private User user;
@Column(name = "show_date", nullable = false, columnDefinition = "DATETIME")
private Date showDate;
@Column(name = "ack_date", nullable = true, columnDefinition = "DATETIME")
private Date ackDate;
@Column(name = "message", length = MESSAGE_MAX_LENGTH, nullable = true)
private String message;
alarmlogrepository(警报日志存储库):
@Transactional(readOnly = true)
public interface AlarmLogRepository extends JpaRepository<AlarmLog, Long>, JpaSpecificationExecutor<AlarmLog> {
@Query("FROM AlarmLog " + //
"WHERE zipato=:zipato " + //
" AND alarmId=:alarmId " + //
" AND subtype='ZONE' " + //
" AND subtypeUuid=:zone " + //
" AND timestamp BETWEEN :start AND :end" + //
" AND needAck=true " + //
" AND size(AlarmLog.acks)=0")
List<AlarmLog> findAlarmLogsByZoneAndDatesAndNeedsAck(@Param("zipato") Zipato p_zipato,
@Param("alarmId") Integer p_alarmId,
@Param("zone") String p_zone,
@Param("start") Date p_start,
@Param("end") Date p_end);
我试过用谷歌搜索这个错误,但找不到这两个错误的精确组合 plural-attribute
没有被认出来。我还试着调试到某个级别,发现 Set
未被识别为集合类型,或者更确切地说 acks Set
不在列表中,因此无法识别为 plural-attribute
.
我不知道怎么解决这个问题。。。
有什么想法吗?
1条答案
按热度按时间cbwuti441#
对于该查询,您应该为实体设置标识符
AlarmLog
并在where条件中按以下方式使用该标识符: