-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 3.2.6 breaks implicit join for collections...
PostPosted: Thu Mar 06, 2008 4:35 pm 
Newbie

Joined: Tue Feb 21, 2006 12:22 pm
Posts: 16
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);
}
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.