2014-11-03 32 views
0

我有這個類,但是當我做一個查詢它拋出一個異常:JPA未能序列

org.hibernate.type.SerializationException:無法序列化

@Entity 
public class Google implements Serializable{ 

@Id 
String nombre; 
String pass; 

public Google() { 
    nombre = "defecto"; 
    pass = "defecto"; 
} 

public Google(String anom, String apass) { 
    nombre = anom; 
    pass = apass; 
} 
//Getters, setters.. 

} 

這是查詢,我使用JPA,休眠和MySQL數據庫,以及類實現Serializable我不知道是至極的問題

public void findNombresGoogle(Map<String, Amigo> anombresAmigos){ 


     List<Google> resultados = new LinkedList<Google>(); 
     Map<String, Amigo> nombresAmigos = anombresAmigos; 
     Query query = entityManager.createNativeQuery("FROM Google google WHERE " 
       + "google.nombre IN (?1)", Google.class); 
     query.setParameter(1, nombresAmigos); 
     resultados = (List<Google>) query.getResultList(); 
} 

回答

0

在下面一行:

query.setParameter(1, nombresAmigos); 

nombresAmigos應該是List<String>,而不是Map<String, Amigo>

+0

我改變這個,但現在它引發另一個錯誤:org.hibernate.exception.SQLGrammarException:無法提取ResultSet – 2014-11-04 13:52:22

+0

不確定這一個,但你可以嘗試添加「選擇谷歌」在你的查詢字符串的開頭。我只有HQL可以從FROM開始,而不是本地查詢(都不是JPQL)。 – 2014-11-04 14:00:49

+0

@AlexisHassler你是對的,只有HQL從FROM開始。 [見這裏](https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html)。原生查詢必須以select開頭。 – Xstian 2014-11-04 15:19:08