开发者

Using hibernate's session.get() with a long ID

开发者 https://www.devze.com 2023-01-27 06:30 出处:网络
I would like to use IDs of type long for my persisted开发者_如何学C objects. However, I find that get() method requires a Serializable object as its ID parameter (discussed here). What is the best wor

I would like to use IDs of type long for my persisted开发者_如何学C objects. However, I find that get() method requires a Serializable object as its ID parameter (discussed here). What is the best workaround?


Use a Long. Hibernate will do the correct mapping for you. And if you use Java 5, you can

long id = ...;
session.get (id);

and the compiler will do the rest.


If you are using java 5/6 it should do that for you with autoboxing. However i would recommend using Long instead of long so that it evaluates to null and not zero.

0

精彩评论

暂无评论...
验证码 换一张
取 消