[英]Proper way to retrieve sequence int after entity save with hibernate and postgresql?
This is how I'm getting the id from save(entity) method: 这就是我从save(entity)方法获取id的方法:
Serializable save = hibernateTemplate.save(article);
return Integer.valueOf(save.toString());
Being a complete noob to hibernate, I just wonder if this is the proper way to do it? 作为一个完整的冬眠菜鸟,我只是想知道这是否是正确的方法呢? I'll appreciate any advice.
我会感激任何建议。
I think it is unnecessary to use Integer.valueOf(save.toString);
我认为没有必要使用
Integer.valueOf(save.toString);
because you know type of your identifier and Hibernate of course too. 因为你知道你的标识符类型和Hibernate。 You can use
(Integer)save
. 你可以使用
(Integer)save
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.