Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-212

Constructor expression permits no other expressions in SELECT clause

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.9.7
    • None
    • query
    • None

    Description

      It seems that it's impossible to run a query with constructor expression beside other expressions in SELECT clause. Take a look at the following test that finishes with ClassCastException when the first element of resultQuery is returned (the 2nd line of the snippet). Am I doing something plain wrong?

      It doesn't work with Hibernate EntityManager 3.3.1, either yet TopLink Essentials 2.0 BUILD 40 runs fine.

      Query query = em.createQuery("SELECT NEW pl.jaceklaskowski.jpa.PewnaKlasa(p.nazwa, o.imie, o.nazwisko, o.numer), o, p.nazwa FROM Projekt p JOIN p.chair o");
      List<Object[]> resultQuery = query.getResultList();
      final Object[] firstElementInQueryResult = resultQuery.get(0);
      assert firstElementInQueryResult.length == 3;
      final Object firstElement = resultQuery.get(0)[0];
      assert firstElement instanceof PewnaKlasa;
      final Object secondElement = resultQuery.get(0)[1];
      assert secondElement instanceof Osoba;
      final Object thirdElement = resultQuery.get(0)[2];
      assert thirdElement instanceof String;

      The exception is as follows (the line number is different though as the test above is incomplete - no class, imports and alike are shown):

      java.lang.ClassCastException: pl.jaceklaskowski.jpa.PewnaKlasa
      at pl.jaceklaskowski.jpa.OpenJPATest.testConstructorExpr(OpenJPATest.java:19)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jlaskowski Jacek Laskowski
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: