-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: HELP ! access to property metadata with SessionFactory
PostPosted: Wed Nov 02, 2005 7:40 am 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 8:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why dont you just keep the Configuration around in the same place as you have your SessionFactory.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 8:39 am 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
I'm not sure to understand what you mean, if you can explain a bit more...
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 8:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how do you get the SessionFactory ?

I assume by some lookup method or injection stuff.

Do the same for the Configuration.

e.g. HibernateUtil.getConfiguration()

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:34 am 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
OK I understand, that was like the third idea I posted
I created a bean which is a "org.hibernate.cfg.Configuration" class, and get it in my test class using applicationContext.getBean("configuration")
I made it work in my test adding a ressource to my configuration object got from my context

cfg.addResource("path/Table.hbm.xml");

but the thing is that I would like to list the ressources directly in my applicationContext.xml file, and as there is not setter to specify a list of ressources to my configuration bean, I still don't know how to do.
I probably just miss a little thing in the doc... argh !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i think you are looking for the spring forum, this is not hibernate specific/related.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 10:06 am 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
oki, I finally found a solution, creating a bean "configuration" in my applicationContext that extends the Configuration class to create the method I would like to use
it works, but I'm not really happy with that, so, let's try on spring forum if there is a solution more simple
thanks a lot


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.