My situation is that I have a Spring Boot application, a PostgreSQL database, and use the hbm2java hibernate Maven plugin to generate the entity classes. The database uses types for which JPA/Hibernate do not have a matching builtin type (example: ltree), so my idea is to use a UserType.
I have created an LTreeType.java class implementing the UserType interface. How can I get hbm2java to use it for every database column of type ltree?
EDIT:
I found out so far that I have to either create a reveng.xml file or subclass DefaultReverseEngineeringStrategy. I have no idea how to tell the plugin to use the former (if it even still exists - this whole mess is completely undocumented), or how to actually get my subclass to work with the Maven plugin.
For the former, <revengFile> does seem to work, although I do end up with the error Execution entity-generation of goal org.hibernate.tool:hibernate-tools-maven:6.2.1.Final:hbm2java failed: Could not resolve named type.
So if anyone knows how to tell either Maven or this darned plugin to add my normal source folder to the classpath, this might potentially solve the problem.
As a final word of advice: stay away as far as possible from hibernate-tools if you have the choice. It's an undocumented mess.
So, I finally managed to do it. It's complicated, to say the least.
First, you have to create your user type - make sure to implement both
UserType<>andJdbcType- in this case, I usedUserType<LTree>and created anLTreeclass to hold the value, but you could also just useString.Then you need to subclass
DelegatingStrategyas well as whatever SQLDialect you are using - in my example, it'sPostgreSQLDialect.ExampleReverseEngineeringStrategy:
ExamplePostgreSQLDialect:
Finally, I used the Maven antrun plugin. This is by far the longest code block, so beware:
It might also work with the "normal" hbm2java Maven plugin, I didn't test that yet, I didn't have the nerve yet. Hopefully this will help someone in as dire a situation as I was.