You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Daniel Jue <te...@gmail.com> on 2008/05/01 23:40:29 UTC

T5 Override/Replace DefaultHibernateConfigurer

Has anyone else tried replacing the DefaultHibernateConfigurer?  I can
add another configurator in my app module like this:

	public static void contributeHibernateSessionSource(
			OrderedConfiguration<HibernateConfigurer> config,
			ClassNameLocator classNameLocator,
			HibernateEntityPackageManager packageManager) {
		config.add("Default", new HibernateConfigurer() {
			public void configure(org.hibernate.cfg.Configuration arg0) {
				HibernateUtil.touch();// just in case this is the
				// first time it's been accessed.
				arg0 = HibernateUtil.getConfiguration();
			}
		});
	}


but it doesn't actually replace the Default configuration.  I haven't
looked but I guess the OrderedConfiguration is based on a List rather
than a Map/Set.

The org.hibernate.cfg.Configuration I want to use is completely set up
programmatically.  It uses set properties and adds in annotated
classes, and makes no use of any XML files.



This is where the original default is added:

public class HibernateModule
...
131        /**
132         * Adds the following configurers: <ul> <li>Default -
performs default hibernate configuration</li> <li>PackageName
133         * - loads entities by package name</li> </ul>
134         */
135        public static void
contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
config,
136                                                            final
ClassNameLocator classNameLocator,
137                                                            final
HibernateEntityPackageManager packageManager)
138        {
139            config.add("Default", new DefaultHibernateConfigurer());
140            config.add("PackageName", new
PackageNameHibernateConfigurer(packageManager, classNameLocator));
141        }


The issue is Tapestry will call configuration.configure on
DefaultHibernateConfigurer() which send hibernate looking for an xml
file.

I'd rather not have a fake hibernate.cfg.xml just to make it work.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Override/Replace DefaultHibernateConfigurer

Posted by Kalle Korhonen <ka...@gmail.com>.
Yes, I know. The point I was making - why should it be needed to override
the default service if you just want to load from some other configuration
file? Rather than a boolean symbol value you could pass the default service
a file name, right?

Kalle


On Tue, May 5, 2009 at 2:25 AM, Kristian Marinkovic <
kristian.marinkovic@porsche.co.at> wrote:

> hi Kalle,
>
> since 5.0.18 (or before, :)) the DefaultHibernateConfigurer is an own
> service,
> therefore it is easy to override it with an alias contribution. if you
> don't want to
> override the service you can set the HibernateConstants.
> DEFAULT_CONFIGURATION
> symbol to false to prevent the service from executing.
>
> g,
> kris
>
>
>
>
>
> Kalle Korhonen <ka...@gmail.com>
> 01.05.2009 19:03
> Bitte antworten an
> "Tapestry users" <us...@tapestry.apache.org>
>
>
> An
> Tapestry users <us...@tapestry.apache.org>
> Kopie
>
> Thema
> Re: T5 Override/Replace DefaultHibernateConfigurer
>
>
>
>
>
>
> This is an old thread, but still relevant to T5.1. I think Daniel is
> completely right; the DefaultHibernateConfigurer always calls
> Configuration.configure() which always sends Hibernate looking for
> hibernate.cfg.xml. I know it's not too difficult to create your own
> implementation of HibernateConfigurer and make it do what you want, but I
> think at least the case where you just want to read from hibernate config
> file with some other name is a fairly common scenario and the filename
> could
> be just a property of DefaultHibernateConfigurer that by default returns
> "hibernate.cfg.xml" but which you could set to a different value. I know
> at
> least Kristian M. has worked on similar issues, what do people think,
> should
> I open an enhancement request for it?
>
> Kalle
>
>
> On Thu, May 1, 2008 at 2:40 PM, Daniel Jue <te...@gmail.com> wrote:
>
> > Has anyone else tried replacing the DefaultHibernateConfigurer?  I can
> > add another configurator in my app module like this:
> >
> >        public static void contributeHibernateSessionSource(
> >                        OrderedConfiguration<HibernateConfigurer> config,
> >                        ClassNameLocator classNameLocator,
> >                        HibernateEntityPackageManager packageManager) {
> >                config.add("Default", new HibernateConfigurer() {
> >                        public void
> > configure(org.hibernate.cfg.Configuration arg0) {
> >                                HibernateUtil.touch();// just in case
> this
> > is the
> >                                // first time it's been accessed.
> >                                arg0 = HibernateUtil.getConfiguration();
> >                        }
> >                });
> >        }
> >
> >
> > but it doesn't actually replace the Default configuration.  I haven't
> > looked but I guess the OrderedConfiguration is based on a List rather
> > than a Map/Set.
> >
> > The org.hibernate.cfg.Configuration I want to use is completely set up
> > programmatically.  It uses set properties and adds in annotated
> > classes, and makes no use of any XML files.
> >
> >
> >
> > This is where the original default is added:
> >
> > public class HibernateModule
> > ...
> > 131        /**
> > 132         * Adds the following configurers: <ul> <li>Default -
> > performs default hibernate configuration</li> <li>PackageName
> > 133         * - loads entities by package name</li> </ul>
> > 134         */
> > 135        public static void
> >
> contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
> > config,
> > 136                                                            final
> > ClassNameLocator classNameLocator,
> > 137                                                            final
> > HibernateEntityPackageManager packageManager)
> > 138        {
> > 139            config.add("Default", new DefaultHibernateConfigurer());
> > 140            config.add("PackageName", new
> > PackageNameHibernateConfigurer(packageManager, classNameLocator));
> > 141        }
> >
> >
> > The issue is Tapestry will call configuration.configure on
> > DefaultHibernateConfigurer() which send hibernate looking for an xml
> > file.
> >
> > I'd rather not have a fake hibernate.cfg.xml just to make it work.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>

Re: T5 Override/Replace DefaultHibernateConfigurer

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi Kalle,

since 5.0.18 (or before, :)) the DefaultHibernateConfigurer is an own 
service, 
therefore it is easy to override it with an alias contribution. if you 
don't want to 
override the service you can set the HibernateConstants.
DEFAULT_CONFIGURATION
symbol to false to prevent the service from executing.

g,
kris





Kalle Korhonen <ka...@gmail.com> 
01.05.2009 19:03
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
Re: T5 Override/Replace DefaultHibernateConfigurer






This is an old thread, but still relevant to T5.1. I think Daniel is
completely right; the DefaultHibernateConfigurer always calls
Configuration.configure() which always sends Hibernate looking for
hibernate.cfg.xml. I know it's not too difficult to create your own
implementation of HibernateConfigurer and make it do what you want, but I
think at least the case where you just want to read from hibernate config
file with some other name is a fairly common scenario and the filename 
could
be just a property of DefaultHibernateConfigurer that by default returns
"hibernate.cfg.xml" but which you could set to a different value. I know 
at
least Kristian M. has worked on similar issues, what do people think, 
should
I open an enhancement request for it?

Kalle


On Thu, May 1, 2008 at 2:40 PM, Daniel Jue <te...@gmail.com> wrote:

> Has anyone else tried replacing the DefaultHibernateConfigurer?  I can
> add another configurator in my app module like this:
>
>        public static void contributeHibernateSessionSource(
>                        OrderedConfiguration<HibernateConfigurer> config,
>                        ClassNameLocator classNameLocator,
>                        HibernateEntityPackageManager packageManager) {
>                config.add("Default", new HibernateConfigurer() {
>                        public void
> configure(org.hibernate.cfg.Configuration arg0) {
>                                HibernateUtil.touch();// just in case 
this
> is the
>                                // first time it's been accessed.
>                                arg0 = HibernateUtil.getConfiguration();
>                        }
>                });
>        }
>
>
> but it doesn't actually replace the Default configuration.  I haven't
> looked but I guess the OrderedConfiguration is based on a List rather
> than a Map/Set.
>
> The org.hibernate.cfg.Configuration I want to use is completely set up
> programmatically.  It uses set properties and adds in annotated
> classes, and makes no use of any XML files.
>
>
>
> This is where the original default is added:
>
> public class HibernateModule
> ...
> 131        /**
> 132         * Adds the following configurers: <ul> <li>Default -
> performs default hibernate configuration</li> <li>PackageName
> 133         * - loads entities by package name</li> </ul>
> 134         */
> 135        public static void
> 
contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
> config,
> 136                                                            final
> ClassNameLocator classNameLocator,
> 137                                                            final
> HibernateEntityPackageManager packageManager)
> 138        {
> 139            config.add("Default", new DefaultHibernateConfigurer());
> 140            config.add("PackageName", new
> PackageNameHibernateConfigurer(packageManager, classNameLocator));
> 141        }
>
>
> The issue is Tapestry will call configuration.configure on
> DefaultHibernateConfigurer() which send hibernate looking for an xml
> file.
>
> I'd rather not have a fake hibernate.cfg.xml just to make it work.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


Re: T5 Override/Replace DefaultHibernateConfigurer

Posted by Kalle Korhonen <ka...@gmail.com>.
This is an old thread, but still relevant to T5.1. I think Daniel is
completely right; the DefaultHibernateConfigurer always calls
Configuration.configure() which always sends Hibernate looking for
hibernate.cfg.xml. I know it's not too difficult to create your own
implementation of HibernateConfigurer and make it do what you want, but I
think at least the case where you just want to read from hibernate config
file with some other name is a fairly common scenario and the filename could
be just a property of DefaultHibernateConfigurer that by default returns
"hibernate.cfg.xml" but which you could set to a different value. I know at
least Kristian M. has worked on similar issues, what do people think, should
I open an enhancement request for it?

Kalle


On Thu, May 1, 2008 at 2:40 PM, Daniel Jue <te...@gmail.com> wrote:

> Has anyone else tried replacing the DefaultHibernateConfigurer?  I can
> add another configurator in my app module like this:
>
>        public static void contributeHibernateSessionSource(
>                        OrderedConfiguration<HibernateConfigurer> config,
>                        ClassNameLocator classNameLocator,
>                        HibernateEntityPackageManager packageManager) {
>                config.add("Default", new HibernateConfigurer() {
>                        public void
> configure(org.hibernate.cfg.Configuration arg0) {
>                                HibernateUtil.touch();// just in case this
> is the
>                                // first time it's been accessed.
>                                arg0 = HibernateUtil.getConfiguration();
>                        }
>                });
>        }
>
>
> but it doesn't actually replace the Default configuration.  I haven't
> looked but I guess the OrderedConfiguration is based on a List rather
> than a Map/Set.
>
> The org.hibernate.cfg.Configuration I want to use is completely set up
> programmatically.  It uses set properties and adds in annotated
> classes, and makes no use of any XML files.
>
>
>
> This is where the original default is added:
>
> public class HibernateModule
> ...
> 131        /**
> 132         * Adds the following configurers: <ul> <li>Default -
> performs default hibernate configuration</li> <li>PackageName
> 133         * - loads entities by package name</li> </ul>
> 134         */
> 135        public static void
> contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
> config,
> 136                                                            final
> ClassNameLocator classNameLocator,
> 137                                                            final
> HibernateEntityPackageManager packageManager)
> 138        {
> 139            config.add("Default", new DefaultHibernateConfigurer());
> 140            config.add("PackageName", new
> PackageNameHibernateConfigurer(packageManager, classNameLocator));
> 141        }
>
>
> The issue is Tapestry will call configuration.configure on
> DefaultHibernateConfigurer() which send hibernate looking for an xml
> file.
>
> I'd rather not have a fake hibernate.cfg.xml just to make it work.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>