Skip to end of metadata
Go to start of metadata

Whats the issue?

Often you will want to make your ids strongly typed, so you are passing round a FooId, not a long.

You can do this in hibernate relatively easily. Once you've set up the base classes, adding new strongly typed ids is trivial.

Write the base class for your strongly typed class

There will be lots of different ones of these in your app probably.

Write your strongly typed class

Set up your class

Set up your class with a strongly typed id, and set up the custom type mapping.

A Base Persistent Object

This is quite handy in hibernate

Implement your base custom type mapper

Implement your hibernate custom type mapper

Now you have all the right things in place to make your custom type mapper just work.

Conclusion.

Now each time you want to make a type safe id, you can just make a pair of typed objects... something that extends AbstractLongId, and something that extends AbstractPersistentLongId.

Labels: