I am trying to setup Hibernate with programmatic configuration. I would like to use addClass so that I can use reflection in my code (so I don't have to specify each class explicitly or specify the configuration file names). However, some classes reference other classes. For example...
<hibernate-mapping package="myPackage">
<class name="ServiceRequest" table="request" lazy="false">
<id name="id"><generator class="identity"/></id>
<many-to-one name="client" class="ServiceClient" column="client_id" cascade="none"/>
<many-to-one name="user" class="ServiceUser" column="user_id" cascade="none"/>
<many-to-one name="method" class="ServiceMethod" column="method_id" cascade="save-update"/>
</class>
When I use a ServiceRequest object to access the db via Hibernate, I get an error 'An association from the table request refers to an unmapped class: myPackage.ServiceMethod'. This makes perfect sense since I never called addClass() for ServiceMethod.
Is it possible for Hibernate to discover and load configuration files dynamically based on a single configuration file?
In this case, that would mean that I would call addClass( myPackage.ServiceRequest) and since that configuration file specifies the package name and class names, Hibernate would also addClass for the ServiceClient, ServiceUser, and ServiceMethod classes (finding their configuration files through the classpath).
|