0

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

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! This completes my first integration test using hibernate. It took several hours, but I can finally persist and read an entity!
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.