views:

138

answers:

1

I'm sick of writing extending PropertyEditorSupport for every single Entity in my system.

I notice that Spring 3.0 has an IdToEntityConverter, but there is really not much documentation on how to use it.

Please comment on the best generic way to convert between id and entity.

+2  A: 

IdToEntityConverter is an internal Spring class. It's non-public, which is why it doesn't appear in the javadoc, but it's registered by default in every context. The class comment says:

Converts an entity identifier to a entity reference by calling a static finder method on the target entity type.

For this converter to match, the finder method must be public, static, have the signature find[EntityName]([IdType]), and return an instance of the desired entity type.

So if you're trying to bind entity class X, then X must have a public static findX(id), or something similar, on class X.

skaffman