Tried to report it:
http://opensource.atlassian.com/project ... e/HHH-3168
Rejected as RTFM...
Here is the code to reproduce, in 3.2.5 it works as expected...
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Query;
@Entity
@NamedQueries(value = {
@NamedQuery(
name = "Cat.by.kitten.name",
query = "select c from Cat c inner join c.kittens as kitten with kitten.name=:name"),
@NamedQuery(
name = "Cat.by.kitten.name2",
query = "select c from Cat c where c.kittens.name=:name")
}
)
public class Cat
{
@Id
protected String name;
@OneToMany
protected Set<Cat> kittens = new HashSet<Cat>();
public Cat(String name)
{
this.name = name;
}
public Set<Cat> getKittens()
{
return kittens;
}
public static void main(String... args)
{
EntityManager entityManager;
entityManager.getTransaction().begin();
Cat mom = new Cat("mom1");
Cat kitten1 = new Cat("mom1.kitten1");
Cat kitten2 = new Cat("mom1.kitten2");
entityManager.persist(mom);
entityManager.persist(kitten1);
entityManager.persist(kitten2);
mom.getKittens().add(kitten1);
mom.getKittens().add(kitten2);
mom = new Cat("mom2");
kitten1 = new Cat("mom2.kitten1");
kitten2 = new Cat("mom2.kitten2");
entityManager.persist(mom);
entityManager.persist(kitten1);
entityManager.persist(kitten2);
mom.getKittens().add(kitten1);
mom.getKittens().add(kitten2);
entityManager.getTransaction().commit();
Query query = entityManager.createNamedQuery("Cat.by.kitten.name");
query.setParameter("name", "mom1.kitten1");
for (Cat cat : (List<Cat>) query.getResultList())
{
System.out.println(cat.name);
}
query = entityManager.createNamedQuery("Cat.by.kitten.name2");
query.setParameter("name", "mom1.kitten1");
for (Cat cat : (List<Cat>) query.getResultList())
{
System.out.println(cat.name);
}
}
}