HQLを使用してデータベースから選択を発行しようとしています
コードは次のとおりです。
public Collection<Link> getAllLinksForDevice(Device device) {
Session session = sessionFactory.getCurrentSession();
String hql = "SELECT Link as l WHERE l.device1 = :deviceId OR l.device2 = :deviceId";
Query query = session.createQuery(hql); <-- Fails here!!
query.setParameter("deviceId",device.getId());
Collection<Link> linkList = query.list();
return linkList;
}
およびリンクエンティティ:
@Id
@Column(name = "id")
@GeneratedValue
private int id;
@ManyToOne
@JoinColumn(name="device1_id")
private Device device1;
@ManyToOne
@JoinColumn(name="device2_id")
private Device device2;
デバイスエンティティ:
@Entity
@Table(name = "device")
public class Device {
@Id
@Column(name = "id")
@GeneratedValue
private int id;
@Column(name = "dns_Name")
private String dnsName;
@Column(name = "ip_address_v4")
private String ipV4;
@Column(name = "device_type")
private int deviceType;
@ManyToOne
@JoinColumn(name="area_id")
private Area area;
しかし、私は例外を受け取ります:
15:10:55,570 DEBUG ErrorCounter:51-:0:0:サブツリーの予期しない終了:0:0:org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3117)のサブツリーの予期しない終了。 hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:720)at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)at org.hibernate.hql.antlr.Hq java:288)org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)at org.hibernate.hql.ast .QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
と:
15:10:55,622エラーパーサー:56-無効なパス:'l.device1' 15:10:55,628 DEBUG ErrorCounter:51-無効なパス:'l.device1'無効なパス:'l.device1' at org.hibernate.hql .ast.util.LiteralProcessor.lookupConstant(LiteralProcessor.java:135)at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:216)at org.hibernate.hql.ast.tree.FromReferenceNode.resolve (FromReferenceNode.java:117)at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113)at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:854)atorg。 hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1293)at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243)at org.hibernate.hql.antlr. java:3722)