Hi Gavin: The demands of the project I'm working on are such that the persistence layer will provide support services for (1) a web site that communicates with an ejb server via stateless session beans wrapping a DAO and (2) a stand-alone application that directly accesses the same DAO without the session wrapper. Databases will be separate, but the data model needs to be available in both places. Because of this dual identity, I need to be able to configure Hibernate differently depending on environment.
The way I understand it, in my DAO, I'd be better off using a SessionFactory that has been preconfigured and bound to JNDI via hibernate.cfg.xml. No problem there as you've adequately allowed for this via named session factories. In my stand-alone application, I'd like to be able to do the same, but there's no JNDI around so I wonder if my only option is to use datastore and properties files for configuration? Looking at the code it seems like named session factories ought to be possible (and useful) without JNDI. If JDNI names were instead configured using a property (connection.jndiname?) then it seems that one could specify named factories in the config, keep all config info in the xml file and obtain the correct factory either by querying SessionFactoryObjectFactory or going against JNDI. What I was hoping was that I'd be able to do something like this: hibernate.cfg.xml ===================== <hibernate-configuration> <session-factory name="localfactory"> <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="connection.url">jdbc:hsqldb:c:/data/hsql/test</property> <property name="connection.username">sa</property> <property name="dialect">cirrus.hibernate.sql.HSQLDialect</property> <!-- mapping files --> <mapping resource="example.hbm.xml"/> </session-factory> <session-factory name="jndifactory"> <property name="jndiname">/env/daofactory</property> <property name="jta.UserTransaction"> java:comp/UserTransaction/ </property> <property name="connection.datasource">/ejbds/</property> <property name="dialect">cirrus.hibernate.sql.HSQLDialect</property> <!-- mapping files --> <mapping resource="example.hbm.xml"/> </session-factory> </hibernate-configuration> This would allow me to set up my DAO more or less as follows. // Abstract inherited by DAO subclasses public BaseHibernateDAO(String config) throws DAOException { protected SessionFactory factory; try { new Configuration(config).configuration.configure(); } catch (HibernateException e) { throw new DAOException(e); } } // Java beans would acquire factory via SessionFactoryObjectFactory public HibernateDAO(String config) extends BaseHibernateDAO throws DAOException { super(config); factory = SessionFactoryObjectFactory.getInstance("localfactory"); } // EJB session beans would acquire factory via JNDI public EJBHibernateDAO(String config) extends BaseDAO throws DAOException { super(config); try { factory = (SessionFactory) new InitialContext().lookup("/env/daofactory"); } catch (NamingException e) { throw new DAOException(e); } } Oh yeah, it'd also be cool if there were a way to share mapping resources with multiple session factories more or less the way you do with properties. I don't think the DTD allows this right now, so in the example I gave above I would have to duplicate all mapping resource declarations despite the fact that both factories use the same set of resources. Forgive me if I've got anything wrong here -- I'm still quite new to Hibernate and this is coming off the top of my head. Maybe there are ways to do this already and I'm simply not seeing them. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel