Hibernate / EclipseLink Interview questions
How do you configure a Customizer to add native EclipseLink mappings not expressible via annotations?
Some EclipseLink capabilities, particularly certain native converters, advanced query redirectors, or fine-grained cache configuration, don't have a corresponding standard annotation. A DescriptorCustomizer gives programmatic access to the entity's ClassDescriptor at startup to configure exactly these cases.
public class ProductCustomizer implements DescriptorCustomizer { @Override public void customize(ClassDescriptor descriptor) { DirectToFieldMapping mapping = (DirectToFieldMapping) descriptor.getMappingForAttributeName("sku"); mapping.setConverter(new SkuUpperCaseConverter()); descriptor.getCachePolicy().setCacheSize(5000); descriptor.getQueryManager().setQueryTimeout(30); } } @Entity @Customizer(ProductCustomizer.class) public class Product { // ... }
Because the customizer runs after annotation and XML mapping processing completes, it always has the final say: any adjustment made inside customize() overrides whatever the declarative configuration set up for that same mapping, which is exactly the point, it's meant to be the last, most specific layer of configuration.
More Related questions...