Hibernate version: 3
Name and version of the database you are using: Oracle 10g
Hi guys,
I would like to add a metadata to "MyProperty" property as following, to specify whether this property is auditable or not (Audit Logging)
Mapping documents:
<hibernate-mapping>
<class name="path.Table" table="TABLE" schema="S">
<meta attribute="generated-class">path.gen.TableGen</meta>
<meta attribute="scope-class" inherit="false">public abstract</meta>
<meta attribute="scope-field">protected</meta>
<id name="tableId" type="long">
<column name="TABLE_ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">s.TABLE_ID</param>
</generator>
</id>
<version name="version" column="VERSION"/>
<property name="myProperty" type="string" column="MY_PROPERTY">
<meta attribute="auditable">true</meta>
</property>
<property name="anotherProperty" type="string" column="ANOTHER_PROPERTY">
</property>
</class>
</hibernate-mapping>
################
In a test class, I try to get the value of my metadata as following
SessionFactory sf = (SessionFactory)applicationContext.getBean("sessionFactory");
Configuration cfg = sf.getConfiguration();
PROBLEM : there is no getConfiguration() method for SessionFactory object, so the code next doesn't work
PersistentClass pc = cfg.getClassMapping(Table.class.getName());
for ( Iterator it = pc.getPropertyIterator() ; it.hasNext() ; ) {
Property p = (Property) it.next();
MetaAttribute ma = p.getMetaAttribute("auditable");
logger.debug(ma.getValue());
}
As my sessionFactory bean is a LocalSessionFactoryBean class (and have a getConfiguration() method), I tried to cast my SessionFactory as LocalSessionFactoryBean, but I obtain a castException
################
I also tried something like that to get a Configuration without using SessionFactory
Configuration cfg = new Configuration();
cfg.addResource("path/Table.hbm.xml");
...
logger.debug(ma.getValue());
It works fine, but as I have more than 100 *.hbm.xml files, this solution doesn't look optimal to me, and why bypass SessionFactory... there is probably a way to get the config from it, or at least a clever way to define my Configuration
################
I also thought about creating a Configuration bean in my applicationContext, but I didn't figured out how to give it access to my 100 *.hbm.xml files
At this point I have no more idea, so please help, any idea would be good.
Thanks a lot
|