-->
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.  [ 3 posts ] 
Author Message
 Post subject: An EJB QL request
PostPosted: Mon Jun 09, 2008 11:56 am 
Newbie

Joined: Fri May 30, 2008 9:05 am
Posts: 18
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 12:27 pm 
Newbie

Joined: Wed May 28, 2008 1:42 pm
Posts: 2
What's the error you're getting or what's the incorrect result you're getting?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 4:54 pm 
Newbie

Joined: Fri May 30, 2008 9:05 am
Posts: 18
In fact, I just test at home, and no problem!!!
I will retry tomorrow at work, it was probably a deployment problem, but strangely, the error message was explicit, something like "errors in sql request".

Too strange!

Sorry for the most stupid post of the month :-)


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

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.