From: Paul S. <pau...@ne...> - 2002-06-12 10:48:40
|
> I've been thinking about the problem of configuring a SessionFactory for > a J2EE application where application code has no control over the system > initialization procedure. I'm thinking that instead of forcing the > application to do this programmatically, there could be a config file > like: While I don't necessarily think this is a bad idea, I'm not sure I quite understand why you say a J2EE app has no control over initialization. What particular app model(s) did you have in mind here? WAR's for servlet engines? EJB apps? other server side models? PaulS. --------------------------------------------- This message was sent using Vianet's Web Based Emailer. http://www.vianet.net.au |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-06-12 14:00:39
|
I expressed this badly, of course. I was meaning to imply no hooks into the system initialization procedure as opposed to hooks into the component _instance_ initialization procedure. You want to configure a single session factory thats shared between potentially many instances of several components (whether these components be servlets or enterprise beans). I think its reasonable to try and make that a bit easier for people. P.S. Does anyone here use Avalon. I've been having a look at their stuff lately and kind of like it and I'm wondering about writing an adapter that exposes hibernate as an Avalon component. But I've never used Avalon so I would probably not get it right on my own...... > While I don't necessarily think this is a bad idea, I'm not sure I > quite understand why you say a J2EE app has no control over > initialization. What particular app model(s) did you have in mind here? > WAR's for servlet engines? EJB apps? other server side models? |
From: Brad C. <bra...@wo...> - 2002-06-13 00:23:34
|
were u thinking of leaving the option to configure programmatically in? the option to configure by file would definitely be usefull in some circumstances. most people r probably aware of the problems with this in the following scenario, but i'll babble on about it anyway. when deploying an application as some sort of archive (eg. war) and u have staging and live servers, u don't want to change the archive file between them (but the configuration is most likely different). so then the xml configuration file has to live outside the archive, which leaves the global classpath to the container. if u have multiple applications using hibernate in the container, u then need multiple configuration files - each file needs a different name and then how do u to tell hibernate to use the correct file for a particular app; or u need one configuration file that can contain the configuration for each application - hibernate still needs to be told which app it is dealing with. ideally we want to have an application's configuration all in once place - including the configuration of third-party frameworks. to achieve this we have writen a wrapper/utility class for hibernate that (among other things) integrates with our application's configuration framework. all our code calls this utility class to get a session, which worries about configuration, etc. this is obviously not a solution for hibernate itself. at this stage i have not come up with any ideas that involve changing hibernate to improve the situation. brad > -----Original Message----- > From: Gavin_King/Cirrus%CI...@ci... > [mailto:Gavin_King/Cirrus%CI...@ci...] > Sent: Wednesday, 12 June 2002 5:41 PM > To: hib...@li... > Subject: [Hibernate-devel] XML SessionFactory configuration >=20 >=20 >=20 > I've been thinking about the problem of configuring a=20 > SessionFactory for > a J2EE application where application code has no control over=20 > the system > initialization procedure. I'm thinking that instead of forcing the > application to do this programmatically, there could be a config file > like: >=20 > <hibernate-configuration> >=20 > <property name=3D"show_sql">false</property> > <property name=3D"use_outer_join">true</property> > <property name > =3D"jta.UserTransaction">java:comp/UserTransaction/</property> >=20 > <session-factory name=3D"/jndi/name"> > <property name=3D"datasource">my/first/datasource</property> > <mapping resource=3D"eg/Foo.hbm.xml"/> > <mapping resource=3D"eg/Bar.hbm.xml"/> > </session-factory> >=20 > <session-factory> > <property name=3D"datasource">my/other/datasource</property> > <mapping file=3D"C:/mapping/my_mappings.hbm.xml"/> > </session-factory> >=20 > </hibernate-configuration> >=20 > What I'm thinking of is that a call to >=20 > Hibernate.configure() >=20 > would look for a resource called hibernate.cfg.xml and use that to > configure and register SessionFactory(s) with JNDI. Subsequent > calls would do nothing. That way application components could all > call Hibernate.configure() when instantiated but we would guarantee > that the factories would only be initialized once. >=20 > I dont want to see an explosion of configuration files but I think > this is reasonable. >=20 > Opinions? Suggestions? >=20 > I will check in some code sometime in the next couple of days for > people to play with.... >=20 > Gavin. >=20 >=20 > _______________________________________________________________ >=20 > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Hibernate-devel mailing list > Hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel >=20 |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-06-13 03:04:51
|
Hi Brad >were u thinking of leaving the option to configure programmatically in? Absolutely. There will always be people who need to do things their own way. Remember we aren't making any assumptions about architecture here. >using hibernate in the container, u then need multiple configuration >files - each file needs a different name and then how do u to tell >hibernate to use the correct file for a particular app; or u need one >configuration file that can contain the configuration for each >application - hibernate still needs to be told which app it is dealing >with. Actually in what I've implemented, this is okay, I think. (depending upon exact arrangement of ClassLoaders.) You can configure multiple SessionFactorys in the same file, with different JNDI names. Then the application looks up its own SessionFactory in JNDI, specifying the correct name for that application. Otherwise, instead of calling Hibernate.configure(), perhaps we could let you call: new Configuration("my/application/hibernate.cfg.xml").configure(); but that would be for special cases. I wish this stuff was in CVS so you can have a look ... it will be there tonight :) >ideally we want to have an application's configuration all in once place >- including the configuration of third-party frameworks. to achieve >this we have writen a wrapper/utility class for hibernate that (among >other things) integrates with our application's configuration framework. I promise this code will continue to work well past version 1. Having never recieved a single complaint/suggestion for the whole Datastore/SessionFactory API, I'm quite convinced it is serving people well. Hence I have no intention of changing/removing it. peace Gavin |