Hibernate version: 2.1.4
Xdoclet version: 1.2
Name and version of the database: MS SQL Server 2000
Build process:
We are using Ant to run an Xdoclet task to generate
*.hbm.xml files from javadoc metadata in our Java source files, then using the
schemaexport task to generate a
schema.ddl document from the
*.hbm.xml files.
Description of issue:
As with many applications, we have enums in our domain model. We have created
UserType classes for them, and we're currently mapping them as properties (
@hibernate.property) when referenced by other classes.
Unfortunately, when mapping enums as properties, the
schemaexport task does not generate a separate "domain data" table (as we call them) and foreign key references from the original tables that contain enum codes.
However, if I map the enum as a
@hibernate.many-to-one relationship in the containing class and map the enum Java source using
@hibernate.class and the requisite property tags, then the table and the foreign keys are generated for me by the
schemaexport task. But then I can't model the enums properly through Hibernate since it wants to construct the enum by calling a default constructor and setting the properties on the enum individually.
The question:
I want to map the enums as both a property (for use in production) and as a many-to-one relationship (only for generating the database schema).
Has anyone found (or created) a good solution for this dichotomy of enum mappings? I'm afraid I'm going to have to use some kind of two-pass mechanism in our
build.xml script to generate one set of
*.hbm.xml files for
schemaexport and another set of
*.hbm.xml files for the application.
I could also see creating a special
@hibernate.enum tag that would behave as a
@hibernate.property tag or a
@hibernate.many-to-one tag, depending on a setting passed into the Xdoclet task.
Or am I going about this problem all wrong? I have read through these documents, but they don't seem to solve the problem I'm having:
UserType for persisting Typesafe Enumerations with a single class
UserType for persisting a Typesafe Enumeration with a VARCHAR column
Thanks for any help you may provide!
Dave