More work on ``@AttributeBinderType`

This commit is contained in:
Steve Ebersole 2021-12-09 12:54:20 -06:00
parent b889375eb6
commit 76c329f919
1 changed files with 18 additions and 2 deletions

View File

@ -5,7 +5,13 @@
:attributeBinderTestDir: {coreProjectDir}/src/test/java/org/hibernate/orm/test/mapping/attributebinder
:extrasdir: extras
`AttributeBinder` is the best thing since sliced bread. Here's why...
For cases where Hibernate does not provide a built-in way to configure the domain
model mapping based on requirements, it provides a very broad and flexible
way to adjust the mapping model through its "boot-time model" (defined in
the `org.hibernate.mapping` package) using its `@AttributeBinderType` meta
annotation and corresponding `AttributeBinder` contract.
An example:
[[domain-customizing-example]]
.AttributeBinder example
@ -17,3 +23,13 @@ include::{attributeBinderTestDir}/YesNo.java[tag=attribute-binder-example, inden
include::{attributeBinderTestDir}/YesNoBinder.java[tag=attribute-binder-example, indent=0]
----
====
The important thing to take away here is that both `@YesNo` and `YesNoBinder` are custom, user-written
code. Hibernate has no inherent understanding of what a `@YesNo` does or is. It only understands that
it has the `@AttributeBinderType` meta-annotation and knows how to apply that through the corresponding
`YesNoBinder`.
Notice also that `@AttributeBinderType` provides a type-safe way to perform configuration because
the `AttributeBinder` (`YesNoBinder`) is handed the custom annotation (`@YesNo`) to grab its configured
attributes. `@YesNo` does not provide any attributes, but it easily could. Whatever `YesNoBinder`
supports.