Hello, i just need any help about an EJB QL query.
I have an entity person that as a ManyToMany relation on itself (because a Person has contacts, wich are Persons too).
My annotations are well written, i have tested.
So, this is my entity Person:
Code:
@Entity
@Table(name="PERSON")
@NamedQueries({
@NamedQuery(name="person.lazyLoadAddresses",
query="SELECT a FROM Address a JOIN a.person p WHERE p.id LIKE :id")
@NamedQuery(name="person.lazyLoadContacts",
query="SELECT contacts FROM Person contacts JOIN contacts.persons AS p WHERE p.id LIKE :id")
})
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String name;
private Collection<Address> addresses;
/* ManyToMany relation attributes */
private Collection<Person> contacts;
private Collection<Person> persons;
public Person(){ }
public Person(String name){
this.name= name;
}
/********************************/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(mappedBy="person")
public Collection<Address> getAddresses() {
return this.addresses;
}
public void setAddresses(Collection<Address> addresses) {
this.addresses = addresses;
}
@ManyToMany
@JoinTable(
name="PERSON_CONTACT",
joinColumns=@JoinColumn(name="ID_PERSON", referencedColumnName="ID"),
inverseJoinColumns=@JoinColumn(name="ID_CONTACT", referencedColumnName="ID")
)
public Collection<Person> getContacts(){
return this.contacts;
}
public void setContacts(Collection contacts){
this.contacts= contacts;
}
@ManyToMany(mappedBy="contacts")
public Collection<Person> getPersons(){
return this.persons;
}
public void setPersons(Collection<Person> persons){
this.persons= persons;
}
}
But I would now get the list of contacts of a person by using an EJB QL query. To do this, at the top of my entity, you can see the named query person.lazyLoadContacts, but it is not correct.
Could someone help me to correct this request please?
Tanks in advance.