我有这个类,但是当我进行查询时它会抛出异常:
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、hibernate 和 MySQL DB,并且该类实现了可序列化,我不知道哪个是问题。
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();
}
最佳答案
在以下行中:
query.setParameter(1, nombresAmigos);
nombresAmigos 应该是 List<String>
,不是Map<String, Amigo>
.
关于java - JPA 无法序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26722875/