0

I have a SQL query and the mapping of the classes. Using openJPA, if the query is made as a @NamedNativeQuery it works fine, returning the correspondent class and the expected result. If it is transformed into a JPQL @NamedQuery it always returns a NoResultException for the getSingleResult method. I tried also the JPA Criteria but it is just not working, at least not in all environments. I cannot reproduce the problem locally, it only occurs in the test system. Locally all of the approaches work ok.

I think that it is a configuration problem, but I haven't found anything.

SQL: SELECT * FROM MY_REL_TABLE map WHERE map.TYPE = ?1 AND map.REGION_ID = ?2

JPQL: SELECT m FROM MyRelationClass m WHERE m.type= :type AND m.region = :region

Does anyone have an idea what could be wrong?

IBM openJPA, Websphere 8.0

azl
  • 109
  • 1
  • 8
  • JPQL is not the same as SQL, so please post the native query and it's JPQL counterpart. – kostja Apr 25 '13 at 14:20
  • I posted the queries, but I do not think the problem lies on the queries as it works locally, but on the config. Thanks anyway. – azl Apr 25 '13 at 14:58

1 Answers1

1

I cannot reproduce the problem locally, it only occurs in the test system.

Are you connecting to the same database in both environments? If not, is it possible that your local database doesn't have the correct data in it?

You could enable OpenJPA SQL trace to see what the JPQL is being translated to:

openjpa.Log=SQL=trace

Also, set the following property to see parameter values :

openjpa.ConnectionFactoryProperties=PrintParameters=true
Rick
  • 3,830
  • 1
  • 18
  • 16
  • Thanks for the hint, I will try it and post the result. – azl Apr 25 '13 at 15:40
  • The problem is that my class Region is abstract and has subclasses, the relationship is eager so the query adds a join and a discriminator constraint (where discriminator in (?, ?) -listing all possible discriminator values-), on the other server this part is different (where discriminator = ? -only the name of the class). I still do not why they are different, but at least I know where is the problem. I will close this question and open a new one. – azl Apr 25 '13 at 17:20
  • I did found out that the server and jpa implementation versions were different (local and remotely). – azl Apr 25 '13 at 17:46