I'm using JPA/Hibernate to interface with a database. My entity classes use annotations. However, apparently in the production environments, the actual database schema is variable (as in, I don't know what it will be). So, to mitigate this, I decided to override the @Table annotations with an XML mapping definition in an orm.xml file. The idea is that upon deployment, the installer can edit a simple .properties file to specify the existing db schema.
I set this up in the Spring configuration like this:
Then, inside that orm.xml (this is simplified):Code:<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="packagesToScan" value="my.packages" /> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>orm.xml</value> </list> </property> </bean>
After I set this up, and verified that it works correctly, I tried to figure out how to substitute the "schema" in the orm.xml file with something from a Java .properties file. I guess I got spoiled in the Spring configuration where I used a PropertyPlaceholderConfigurer bean, and just assumed this was doable. How can I accomplish this? Basically, what I want to do in the orm.xml file is something similar to:Code:<entity-mappings> <entity class="my.packages.MyRecord" name="myRecord"> <table name="schema.MYTABLE" /> </entity> </entity-mappings>
If this is not possible inside the orm.xml file, is there any way to move the configuration that I currently have in the orm.xml file into my Spring application context configuration file?Code:<table name="${schema-property}.MYTABLE" />
If there really is no way to do this, can someone direct me to the class that I need to subclass in order to add this functionality? I am a victim of being unable to make changes to how the databases are configured, and I'm already going past due on this task.
Any help would be greatly appreciated.


Reply With Quote