StringBuilder queryString = new StringBuilder(" FROM Organisation org ")
.append(" INNER JOIN Abonne a ")
.append(" WHERE org.idOrganisation = a.organisation ");
起因:org.hibernate.hql.internal.ast.QuerySyntaxException:预期要加入的路径!
我正在为Abonne a的org.idOrganisation = org.code的a.organisation订单获得INNER JOIN的期望路径。
Abonne实体 正式实体具有组织外键 @加入表格id_org
@Entity
@Table(name = "T_ABONNE")
public class Abonne {
private static final long serialVersionUID = -7500240243978256087L;
@Id
@Column(name = "ID_ABONNE", columnDefinition = "CHAR(32)")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String idAbonne;
@Column(name = "LIB_NOM", length = 200, nullable = false)
private String nom;
@Column(name = "BOO_ACTIF", nullable = false)
private Boolean actif;
@Column(name = "DAT_DATE_EXPIRATION", length = 10)
@Type(type="utcType")
private Date dateExpiration;
@Column(name="NO_MAXIM_DE_UTILISATEURS", length = 5000)
private Integer noMaxUsers;
@ManyToOne
@JoinColumn(name="ID_LANGUAGE", nullable=false)
@Index(name = IndexNameUtil.T_ABONNE_ID_LANGUAGE_IDX)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Language language;
@ManyToOne
@JoinColumn(name="ID_THEME", nullable=false)
@Index(name = IndexNameUtil.T_ABONNE_ID_THEME_IDX)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Theme theme;
@ManyToOne
@JoinColumn(name="ID_FONT", nullable=false)
@Index(name = IndexNameUtil.T_ABONNE_ID_FONT_IDX)
private Font font;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="ID_ORG", nullable=false, updatable=false)
@Index(name = IndexNameUtil.T_ABONNE_ID_ORG_IDX)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Organisation organisation;
}
组织实体 这是拥有idOrganisation的组织实体
@Table(name = "T_ORGANISATION")
public class Organisation {
private static final long serialVersionUID = 5348078630581306005L;
public static final String COLUMN_ID_ORGANISATION = "ID_ORGANISATION";
@Id
@Column(name = COLUMN_ID_ORGANISATION, columnDefinition = "CHAR(32)")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String idOrganisation;
@Column(name = "LIB_NOM", nullable = false, length=250)
private String nomOrganisation;
@Column(name = "LIB_CODE", length=100)
private String code;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="ID_FICHIER")
@Index(name = IndexNameUtil.T_ORGANISATION_ID_FICHIER_IDX)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private File logo ;
}
答案 0 :(得分:0)
这应该可以工作:-
StringBuilder queryString = new StringBuilder(" FROM Abonne a ")
.append(" INNER JOIN a.organisation org ")
.append(" WHERE org.idOrganisation = a.organisation ");
答案 1 :(得分:0)
按如下所示更改查询:
StringBuilder queryString = new StringBuilder("select a.organisation FROM Abonne a ")
使用a.organistion时,它将自行在休眠状态下创建连接。
或者
在组织中添加列表以进行双向映射并使用以下查询。
@Table(name = "T_ORGANISATION")
public class Organisation {
private static final long serialVersionUID = 5348078630581306005L;
public static final String COLUMN_ID_ORGANISATION = "ID_ORGANISATION";
@Id
@Column(name = COLUMN_ID_ORGANISATION, columnDefinition = "CHAR(32)")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String idOrganisation;
@Column(name = "LIB_NOM", nullable = false, length=250)
private String nomOrganisation;
@Column(name = "LIB_CODE", length=100)
private String code;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="ID_FICHIER")
@Index(name = IndexNameUtil.T_ORGANISATION_ID_FICHIER_IDX)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private File logo ;
@OneToMany(mappedBy="organisation")
List<Abonne> abonnes;
StringBuilder queryString = new StringBuilder(" FROM Organisation org ")
.append(" JOIN org.abonnes a ")
.append(" WHERE org.idOrganisation = a.organisation.idOrganisation ");