I am stuck with the following exception:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet.
I have the following class Organisation
. Take a look at my @ManyToMany
attributes sousTraitants
and donneurDOrdre
.
@Entity
@Table( name = "t_organisation" , indexes = {
} )
public class Organisation implements Serializable {
@Id
@Column( name = "N_ID" )
@GeneratedValue( strategy = GenerationType.IDENTITY )
protected Long id;
@Basic
@Column( name = "C_RAISONSOCIALE", nullable = false )
private String raisonSociale;
@OneToMany( fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, mappedBy = "organisation" )
private Set<Individu> personnels;
@ManyToMany(cascade = { CascadeType.ALL })
@JoinTable(
name = "SousTraitant_Organisation",
joinColumns = { @JoinColumn(name = "N_DONNEURDORDRE_ORGID") },
inverseJoinColumns = { @JoinColumn(name = "N_SOUSTRAITANT_ORGID") }
)
private Set<Organisation> sousTraitants = new HashSet<>();
@ManyToMany(mappedBy = "sousTraitants")
private Set<Organisation> donneurDOrdre = new HashSet<>();
I tried the following query to retrieve a list of Organisation
:
List<Organisation> result = HibernateUtil.getCurrentSession()
.createQuery( "SELECT o FROM " + Organisation.class.getName() + " o JOIN o.sousTraitants WHERE o.donneurDOrdre = :idDonneurDOrdre", Organisation.class )
.setParameter( "idDonneurDOrdre", idDonneurDOrdre )
.getResultList();
But I still have the same exception message, and I'm not whether it's my @ManyToMany
annotation which is wrong or my query.