0

I have this:

@ManyToOne( fetch=FetchType.LAZY )
@Required
@NoFrame
@JoinColumn(name="plaga_id")
@DescriptionsList
private PlagaOEnfermedad plaga;

@Required
@ManyToOne( fetch=FetchType.LAZY )
@DescriptionsList(depends="this.plaga", condition="",
         descriptionProperties="nombreCientifico")
private InsectoAuxiliar auxiliar;

which indicates that auxiliar is a combo with InsectoAuxiliar.nombreCientififico as contents. Also, the "depends" indicates that this combo contents will load on the other combo selection event (the other is "plaga").

The problem is that I don't know how to generate the condition, taking into account that InsectoAuxiliar contains this:

@ManyToMany( fetch=FetchType.LAZY )
@JoinTable(name="insectos_plagas",
        joinColumns={@JoinColumn(name="auxiliar_id",referencedColumnName="nombreCientifico")},
        inverseJoinColumns={@JoinColumn(name="plaga_id",referencedColumnName="nombre")},
        uniqueConstraints=@UniqueConstraint(columnNames = { "plaga_id", "auxiliar_id" }))
private Collection<PlagaOEnfermedad> plagasAplicables;

And I want to filter my combo depending on "plagasAplicables.nombre". The question is, how should I write the JPQL query to use the Collection?. "Condition" on the descriptionList (the combo) indicates the sentence after a "WHERE" in JPQL but dont know how to write it...

For example, from other questions I have tried this:

@DescriptionsList(depends="this.plaga", condition="? MEMBER OF e.plagasAplicables.nombre", )

But I get this error:

Caused by: org.hibernate.QueryException: illegal attempt to dereference collection [insectoaux0_.nombreCientifico.plagasAplicables] with element property reference [nombre] [SELECT e.nombreCientifico, e.nombreCientifico, e.nombreCientifico from org.openxava.recetas.model.InsectoAuxiliar e WHERE :p0 MEMBER OF e.plagasAplicables.nombre]

Any help will be much appreciated...

Thanks in advance,

Jose.

kankamuso
  • 441
  • 1
  • 3
  • 18

1 Answers1

0

Finally !!:

@DescriptionsList(depends="this.plaga", condition="? IN (SELECT p.nombre FROM PlagaOEnfermedad p WHERE p.nombre MEMBER OF e.plagasAplicables)",
         descriptionProperties="nombreCientifico")

Thats all!

kankamuso
  • 441
  • 1
  • 3
  • 18