2 つのエンティティと、特定の列挙型のフィールドを持つエンティティがあります。ここで、特定の列挙値を持つものをすべて取得したいと考えています。
@Entity
@Table(name = "AlarmEvent")
@XmlRootElement
public class AlarmEvent implements Identifiable {
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "guid")
@Column(name = "Id", columnDefinition = "uniqueidentifier")
private String id;
@ManyToOne
@JoinColumn(name = "AlarmType_Id")
@XmlJavaTypeAdapter(EntityAdapter.class)
private AlarmEventDefinition alarmType;
@Column(name = "Timestamp", nullable = false)
private Date timestamp;
@Override
@XmlTransient
public String getIdentifier() {
return id;
}
public AlarmEventDefinition getAlarmType() {
return alarmType;
}
public void setAlarmType(AlarmEventDefinition alarmType) {
this.alarmType = alarmType;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
}
そして2番目のエンティティ
@Entity
@Table(name = "AlarmEventDefinition")
@XmlRootElement
public class AlarmEventDefinition implements Identifiable {
public static enum AlarmEventDefinitionType {
Start, End, Trigger, Report
}
@Id
@Column(name = "Id")
private Integer id;
@Column(name = "Name_DE", length = 256)
private String nameDe;
@Column(name = "Type")
@Enumerated(EnumType.STRING)
private AlarmEventDefinitionType type;
@OneToMany(mappedBy = "alarmType", fetch = FetchType.LAZY)
@XmlTransient
private List<AlarmEvent> events;
public List<AlarmEvent> getEvents() {
return events;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNameDe() {
return nameDe;
}
public void setNameDe(String nameDe) {
this.nameDe = nameDe;
}
public AlarmEventDefinitionType getType() {
return type;
}
public void setType(AlarmEventDefinitionType type) {
this.type = type;
}
}
今、私はこれをしたいです
List<AlarmEvent> result = (List<AlarmEvent>) session.createCriteria(AlarmEvent.class)
.add(Restrictions.eq("alarmType.type", AlarmEventDefinitionType.Trigger))
.list();
すべての AlarmEvents を取得するには、AlarmEventDefinitions タイプを Trigger にします。休止状態 言います:
org.hibernate.QueryException: プロパティを解決できませんでした: alarmType.type of: datamodel.AlarmEvent