Я пытаюсь преобразовать этот SQL-запрос в HQL:HQL: Недопустимый путь в множества различных Присоединяется
SELECT
elements of t2
FROM
debitant t2
INNER JOIN debit t3 ON t2.id_debit = t3.id
INNER JOIN l_debit_saci t7 ON t3.id = t7.id_debit AND t7.principal = 1
INNER JOIN rushServices t8 ON t7.code_acs = t8.acs
INNER JOIN bulletin_correction t10 ON t2.id = t10.id_debitant
LEFT OUTER JOIN l_debitant_complement t9 ON t2.adr_info = t9.id
INNER JOIN commune t6 ON t3.adr_cc = t6.id
WHERE
t2.id = @debitant_id AND t10.annee = @PECAnnee
ORDER BY
t3.adr_cp , t2.id
HQL код, который я попытался это:
buffer = new StringBuilder();
buffer.append("SELECT D ");
buffer.append("FROM " + getEntityClassName() + " D ");
buffer.append("INNER JOIN FETCH D.debit DE ");
buffer.append("INNER JOIN FETCH DE.sacis DS ");
buffer.append("INNER JOIN FETCH DS.service RS ");
buffer.append("INNER JOIN BulletinCorrectionMod.debitant BC ");
buffer.append("LEFT OUTER JOIN D.adresseInfo DEC ");
buffer.append("INNER JOIN FETCH DE.adresseCommune CO ");
buffer.append("WHERE DS.principal = 1 ");
buffer.append("AND D.id = :debitantId ");
buffer.append("AND DC.annee = :annee ");
buffer.append("ORDER BY DE.adresseCodePostal, D.id");
hqlQuery = session.createQuery(buffer.toString());
hqlQuery.setInteger("debitantId", debitantId);
hqlQuery.setInteger("annee", year);
Этот код возврата эта ошибка: Недопустимый путь: 'BulletinCorrectionMod.debitant'
Здесь все DAO с их отношений:
DebitantMod:
@Entity
@Table(name = "debitant")
public class DebitantMod implements Serializable
{
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_name")
@SequenceGenerator(name = "sequence_name", sequenceName = "debitant_id_seq")
private Integer id = null;
@Column(name = "adr_info", nullable = true)
private Integer adresseInfo = null;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_debit", nullable = false)
private DebitMod debit = null;
....
}
DebitMod:
@Entity
@Table(name = "debit")
public class DebitMod implements Serializable
{
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_name")
@SequenceGenerator(name = "sequence_name", sequenceName = "debit_id_seq")
private Integer id = null;
@OneToMany(mappedBy = "debit", fetch = FetchType.LAZY)
private Set<DebitantMod> debitants = null;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "adr_cc", nullable = true, columnDefinition = "bpchar")
private CommuneMod adresseCommune = null;
...
}
DebitSaciMod:
@Entity
@Table(name = "l_debit_saci")
public class DebitSaciMod implements Serializable
{
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_name")
@SequenceGenerator(name = "sequence_name", sequenceName = "l_debit_saci_id_seq")
private Integer id = null;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_debit", nullable = false)
private DebitMod debit = null;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "code_acs", nullable = false)
private RushServiceMod service = null;
...
}
RushServiceMod:
@Entity
@Table(name = "rushservices")
public class RushServiceMod implements Serializable
{
@Id
@Column(name = "acs", nullable = false)
private String acs = null;
...
}
BulletinCorrectionMod:
@Entity
@Table(name = "bulletin_correction")
public class BulletinCorrectionMod implements Serializable{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_debitant", nullable = false)
private DebitantMod debitant = null;
@Column(name = "annee", nullable = false)
private Integer annee = null;
...
}
DebitantComplementMod:
@Entity
@Table(name = "l_debitant_complement")
public class DebitantComplementMod implements Serializable{
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_name")
@SequenceGenerator(name = "sequence_name", sequenceName = "l_debitant_complement_id_seq")
private Integer id = null;
...
}
CommuneMod:
@Entity
@Table(name = "commune")
public class CommuneMod implements Serializable
{
@Id
@Column(name = "id", nullable = false, columnDefinition = "bpchar")
private String id = null;
...
}
Удалите слово FETCH в HQL и попробуйте ag ain :) – Dherik