1

I created query method in Spring Data JPA repository. I used method naming conventions. I'm not sure but it looks like Spring Data made query cache for it. I have those entity:

public class Feature {

    private String desc;

    private FeatureFor featureFo;

}

public enum FeatureFor {

    ABC, DEF, XYZ;

}

In repository I created method with name:

public List<Feature> findByFeatureForIn(List<FeatureFor> featureFors);

This method is invoked twice from different servises. First time when it's invoked I can see generated query in console which is something like this:

SELECT ...... WHERE ((t0.featureFor = ? OR t0.featureFor = ?) AND t0.featureFor IS NOT NULL) [params=(String) ABC, (String) DEF]

This is ok. But When method is invoked via second service I can see same select generated with the same parameters. I'm sure that in featureFors parameter there were ABC and XYZ. But it's completely ignored. I also tried to use featureFors with one ABC value contained in (in first invoked service). In this case query generated was something like this:

SELECT ...... WHERE (t0.featureFor = ? AND t0.featureFor IS NOT NULL) [params=(String) ABC, (String) DEF]

Second service passed same params (ABC and XYZ) but the generated query and params did not change (it's same which generated in the first service). Does anybody knows if Spring Data creates cache for queries? I didn't realize I made some mistake. Maybe I did. I'm using OpenJPA. Thank you for your help.

The persistence configuration looks like this:

<?xml version="1.0"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="openjpa">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <class>...difened entities here (including Feature)...</class>      
        <properties>
            <property name="openjpa.Log" value="DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
            <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
            <property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/>
        </properties>
    </persistence-unit>
</persistence>
Marko
  • 101
  • 6
  • Query cache has to be enabled explicitly. Show us your persistence configuration so we don't have to guess how it looks like. – Rafal G. Apr 18 '15 at 22:52
  • I have just added it. Thank you for your answer. – Marko Apr 19 '15 at 07:16
  • Hi Marko, Did you figure this issue out? I might get the same problem as you had. My question: http://stackoverflow.com/questions/38141342/failed-to-query-by-spring-data-jpa-query-methods-with-suffix-in-due-to-the-cache Thanks – Bruce Jul 25 '16 at 07:55
  • What version of spring-data-jpa and openjpa you used? I am using spring-data-jpa 1.10.2 and openjpa 2.4.1, but if I used spring-data-jpa 1.10.2 and openjpa 2.2.2, it will works well. – Bruce Jul 25 '16 at 10:08
  • Hi, Sorry for later answer. I don't remember what was the problem. But I think It was my fault. I have feeling method will be invoked three times from two services. So I did not handle it when I debug application. – Marko Aug 01 '16 at 10:45

0 Answers0