这就是我从 save(entity) 方法获取 id 的方式:
Serializable save = hibernateTemplate.save(article);
return Integer.valueOf(save.toString());
作为一个彻头彻尾的 hibernate 新手,我只是想知道这是否是正确的 hibernate 方式? 我将不胜感激任何建议。
最佳答案
我认为没有必要使用 Integer.valueOf(save.toString);
因为您知道标识符的类型,当然也知道 Hibernate。您可以使用(Integer)save
。
关于java - 使用 hibernate 和 postgresql 保存实体后检索序列 int 的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3468231/