5 Replies Latest reply on Aug 31, 2005 10:25 AM by jactor

    EJBQL

      I have a strange problem with my EJBQL when I am retrieving beans (EJB 3.0). The query results in returning the beans * 4 if there is more than one bean persisted...

      The query:
      select b.bean from aBean as b
      where b.name = :name

      I suspect that I can solve this with knowledge of the EJBQL, but I don't have the best resources. So if anyone know any good links for this, please provide this as well...

      Regards

        • 1. Re: EJBQL

          This will give me a major headache if I don't get it fixed. So I hope you can help me with some suggestions.

          Here is the original query:
          select u.guests
          from nu.hjemme.ejb.entity.User as u
          inner join fetch u.guests
          where u.userName = :userName
          order by u.guests.conceived desc

          Additonal information:
          guests.conceived is a non nullable field which is of type long.
          guests is an entity bean which is of the relation one to many and can be nullable....

          • 2. Re: EJBQL

            I have created a temporary solution that ignores the extra beans if it has an id that is already used. This will work well with few users, but when the load ascends, it will be a problem...

            I have no clue to what is wrong so please give me a hint...

            I am going to sing a Beatles song...
            HELP... I need somebody...
            HELP... Not just anybody...
            HELP... I need somone...
            HEEEELP...

            And I will give another issue (but this is not searius): I can't use an inner join fetch... to get beans if there exists beans with no instances in the join. They will not be returned...
            Ex:
            from an.package.Bean as b
            inner join b.anotherBean

            The beans that doesn't contain anotherBean will not be returned? I expected that they would be returned, but have a null reference...

            If there exists some good links to read more about the EJBQL, please provide this.

            • 3. Re: EJBQL

              My headache are starting to grow. I have stated the word distinct in the query, but this does not help and in order to get it to compile I had to erase the 'order by'-clause which is not desireable.

              The query with distinct:
              select distinct u.guests
              from nu.hjemme.ejb.entity.User as u
              inner join fetch u.guests
              where u.userName = :userName

              Is there a way to make this query native? I tried to state it as a native query, but then it won't compile because it can't find the column named id (the primary key column in the create table statement which the EJB container has generated).

              Help!
              Does anyone have an other solution for getting a unique collection (that is a collection which contains unique beans in order of its id) which is a collection which is refrenced by another bean?

              • 4. Re: EJBQL

                I have reduced the return value of beans from x4 to x2... Help me to get rid of the last one that is coming twice...

                I now get the entity bean (User) and return its collection of beans (called guests).

                Query:
                from nu.hjemme.ejb.entity.User as u
                inner join fetch u.guests
                where u.userName = :userName

                When I have the user, I return its collection (user.getGuests()). By doing this the returned number is (guests)x2 (???) and I also lost the order by sequence but when returning an collection from an instance of another bean, they are returned in the order they where created so I don't need it... But why do they come twice?

                • 5. Re: EJBQL

                  I just upgraded to the 4.0.3RC2 release and the problem disappeared!!!!

                  No more headaches!!!!

                  :)