The property is hibernate.connection.datasource
you are not allowed to abbreviate outside of the .cfg.xml. > Alright, I take back my "duh". Setting the connection datasource > property does not seem to do anything. Should I file a bug report? > Here's some sample code: > > ## hibernate.cfg.xml > <session-factory name="java:comp/env/hibernate/SessionFactory"> > <!-- properties --> > <property > name="connection.datasource">java:comp/env/jdbc/vergil</property> > .... > </session-factory> > > ##Initialization code > Configuration cfg = new net.sf.hibernate.cfg.Configuration(); > cfg.configure(); > System.out.println("Connection was " + > cfg.getProperty("connection.datasource")); > System.out.println("Specifying a connection: " + datasourceName); > cfg.setProperty("connection.datasource", datasourceName); > System.out.println("Connection is " + > cfg.getProperty("connection.datasource")); > sf = cfg.buildSessionFactory(); > > ##stdout > Connection was java:comp/env/jdbc/vergil > Specifying a connection: java:comp/env/jdbc/vergilpublic > Connection is java:comp/env/jdbc/vergilpublic > net.sf.hibernate.HibernateException: Could not find datasource: > java:comp/env/jdbc/vergil > at > net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:51) > at > net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83) > at > net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:153) > at > net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627) > at > com.lokitech.hibernate.HibernateConfiguration.contextInitialized(HibernateConfiguration.java:53) > ... > > Gavin King wrote: >> Of course you can set properties programmatically!! >> >> >> new Configuration().configure().setProperty(...).buildSessionFactory() >> >> >>>I'm using Hibernate is a servlet container, and I have a servlet context >>>listener that configures Hibernate. What I noticed was that I had to >>>put the JNDI datasource location in both the web.xml (for JSTL and >>>servlets to use) and in the hibernate.cfg.xml. >>> >>>What I did was a bit of a hack... I had the servlet context listener >>>parse the hibernate.cfg.xml, find the datasource name, and then replaced >>>it with what was in web.xml. I could then hand that DOM object to the >>>hibernate configure method, and hibernate would start great. >>> >>>The problem I hit today was that with this solution, the XML parsing of >>>hibernate.cfg.xml was called from a class outside of the hibernate.jar, >>>so then it couldn't get to the DTD in the jar. >>> >>>Any other suggestions for workarounds? There are a number of ways to >>>support loading a configuration, but there doesn't seem to be a way to >>>set properties programmatically. Any thoughts? > > > > -- > Serge Knystautas > President > Lokitech >> software . strategy . design >> http://www.lokitech.com > p. 301.656.5501 > e. [EMAIL PROTECTED] > > ------------------------------------------------------- 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