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.
精彩评论