Bonjour,

Je suis actuellement en train de developper une application utilisant Spring et JPA. Et je cherche à recupérer le contenu d'une table appelée Product en filtrant par rapport à une liste d'identifiant. Pour cela, j'utilise la méthode findAll(Iterable<ID>) d'une interface qui hérite de CrudRepository.
Sur l'appel de la method findAll, j'ai une exception m'indiquant qu'il ne peut pas comparer un objet Integer à un objet Iterable. Mais, je ne comprend pas pourquoi spring compare mon Integer à un objet Iterable.

Si quelqu'un a une idée je suis preneur.

Voici l'exception :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Filter invalid. Cannot compare field id of type java.lang.Integer to value of type java.lang.Iterable. Numeric comparisons must be between numeric types only. To enable such comparisons for backwards-compatibility, add "QuotedNumbersInQueries=true" to the org.apache.openjpa.Compatibility setting in your configuration.; nested exception is <openjpa-2.2.2-r422266:1468616 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Filter invalid. Cannot compare field id of type java.lang.Integer to value of type java.lang.Iterable. Numeric comparisons must be between numeric types only. To enable such comparisons for backwards-compatibility, add "QuotedNumbersInQueries=true" to the org.apache.openjpa.Compatibility setting in your configuration.
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:943)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
	org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
	org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
La classe "service" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Service("ProductServiceImpl")
public class ProductServiceImpl implements ProductService{
 
	@Autowired
	private ProductDao productDao;
 
	@PersistenceContext
	private EntityManager entityManager;
 
	@Override
	public List<JpaProduct> getProductList(String username) {
		ArrayList<Integer> productIDs = new ArrayList<Integer>();
		productIDs.add(new Integer(2));
		productIDs.add(new Integer(3));
 
		return (List<JpaProduct>) productDao.findAll(productIDs);
	}
}
La table SQL :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
CREATE  TABLE Product (
  id INTEGER NOT NULL,
  name VARCHAR(50) NOT NULL ,
  lastSettingsUpdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
  PRIMARY KEY (id)
);
L'entité :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@Entity
@Table(name = "Product")
public class JpaProduct implements Serializable {
	/**
         * 
         */
	private static final long serialVersionUID = 6602731453809974373L;
 
	@Id
    @Column(name = "id", nullable = false)
    private Integer id;
 
    @Column(name = "name", length=50, nullable = false)
    private String name;
 
    @Column(name = "lastSettingsUpdate", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private GregorianCalendar lastSettingsUpdate;
 
    public JpaProduct() {
    }
 
    public JpaProduct(Integer id, String name, GregorianCalendar lastSettingsUpdate) {
        this.id = id;
        this.name = name;
        this.lastSettingsUpdate = lastSettingsUpdate;
    }
 
	public Integer getId() {
		return id;
	}
 
	public void setId(Integer id) {
		this.id = id;
	}
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		this.name = name;
	}
 
	public GregorianCalendar getLastSettingsUpdate() {
		return lastSettingsUpdate;
	}
 
	public void setLastSettingsUpdate(GregorianCalendar lastSettingsUpdate) {
		this.lastSettingsUpdate = lastSettingsUpdate;
	}
}
Le repository:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
public interface ProductDao extends CrudRepository<JpaProduct, Integer> {}