Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Suggestion : Allow objects to be used to config Hiberate
PostPosted: Wed Dec 22, 2004 8:25 am 
Newbie

Joined: Mon Feb 02, 2004 4:18 pm
Posts: 16
I'm continuing a thread from the hibenate blog to the forum so more people can join in the discussion. Read the comments on this blog http://blog.hibernate.org/cgi-bin/blosx ... #threebeta to understand the reasoning behind this post.

Currently, the configuration object takes a properties object to set up hibernate. If you want to provide a class, like a cach provider, then you specify the name of the property and the name of the class (which must contain a 0-args constructor) which hibernate will try and instantiate. The problem with this mechanism is that you cannot pass in an existing object such as a cache that you resolve from JNDI.

What I propose is using the map interface as an option instead of properties which wouldn't break backwards compatibilty is as much as you would only have to change the Configuration class to pass a map, the Environment class to add new constants for preconfigured objects and the SettingsFactory class to use the preconfigured classes from the map and cast to CacheProvider from the object, but continue to cast other objects to strings as before.

An example of the spring configuration for IoC would then look like this
<pre>
[bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"]
[property name="mappingResources"]
    [value]product.hbm.xml[/value]

[/property]
[property name="hibernateProperties"]
[map]
[entry key="hibernate.dialect"]
[value]net.sf.hibernate.dialect.MySQLDialect[/value]
[/entry]
[entry key="hibernate.cacheProvider.ioc"]
[ref bean="cacheProvider" /]
[/entry]
[/map]
[/property]
[/bean]
</pre>

How do you feel about this change, would other people also benefit from such a change? Is there anything I've missed here that might make the solution more difficult than I've suggested? I've already coded an example that I'm going to test later today, I'll feedback on the results then.

Graham


Top
 Profile  
 
 Post subject: clearer idea ;)
PostPosted: Wed Dec 22, 2004 10:37 am 
Newbie

Joined: Mon Feb 02, 2004 4:18 pm
Posts: 16
For my demo, I'm using spring for IoC so to make the minimum number of changes I've added a new method to LocalSessionFactoryBean to accept a map from the spring config file which creates a map from the properties file and then the configuration object doesn't need to be modified. Then all you need is to add new constants to the Environment class for any objects (like "hibernate.cacheProvider.ioc") and then modify the Settingsfactory to use the object in preference to the property so it doesn't use the name of a class.

Just getting a working demo working...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 5:54 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Is there any progress on this?

What about Hibernate3? Is it already supporting this notion?

Rgds, Ales


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.