Comment interroger pour les valeurs de la Carte avec Spring Data JPA?

donc mon modèle de base de données qui va comme ceci: j'ai Stores et tous les Store a un nom localisé. J'ai donc choisi pour représenter le nom localisé comme un Map comme ceci:

public class Store {
   private Map<Locale,LocalizedValue> name;
}

comme vous pouvez le voir c'est une Carte de <Locale, LocalizedValue> où la LocalizedValue est une classe comme ceci:

@Embeddable
public class LocalizedValue {

   @Column(name = "value")
   private String value;
}

et tout fonctionne très bien. Mais j'ai un problème lorsque je veux requête de mon Ressort des Données JPA référentiel et de trouver tous les magasins avec un nom anglais. Donc, mon référentiel méthode ressemble à ceci:

Store findByName(Map.Entry<Locale, LocalizedValue> name);

mais elle en jette cette exception:

 2014-10-07 23:49:55,862 [qtp354231028-165] ERROR: Parameter value [en=Some Value] did not match expected type [com.test.LocalizedValue(n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [en=Some Value] did not match expected type [com.test.LocalizedValue (n/a)]
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [en=Some Value] did not match expected type [com.test.LocalizedValue (n/a)]; 
nested exception is java.lang.IllegalArgumentException: Parameter value [en=Some Value] did not match expected type [com.test.LocalizedValue (n/a)]
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:216)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)

Alors j'ai changé mon référentiel méthode pour être comme ceci:

Store findByName(LocalizedValue name);

mais j'ai eu cette exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'name1_.pk' in 'where clause'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

J'ai aussi essayé d'utiliser, Contient, dans la méthode de requête - toujours pas de chance.

Donc ma question est: Est-il un moyen pour rechercher les magasins avec un nom anglais 'Valeur'?

OriginalL'auteur Petar Tahchiev | 2014-10-07