gpt4 book ai didi

java - JPA 无法序列化

转载 作者:行者123 更新时间:2023-11-29 23:28:59 25 4
gpt4 key购买 nike

我有这个类,但是当我进行查询时它会抛出异常:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com