I'm using Hibernate 3.3, Tomcat 6, and Eclipse Galileo and I get the following exception from Configuration.configure().buildSessionFactory():
13:00:35,843 INFO SessionFactoryObjectFactory:109 - Factory name: java:comp/env/jdbc/bmf 13:00:35,843 INFO NamingHelper:49 - JNDI InitialContext properties:{} 13:00:35,843 WARN SessionFactoryObjectFactory:121 - Could not bind factory to JNDI javax.naming.NamingException: Context is read only at org.apache.naming.NamingContext.checkWritable(NamingContext.java:903) at org.apache.naming.NamingContext.bind(NamingContext.java:831) at org.apache.naming.NamingContext.rebind(NamingContext.java:208) at org.hibernate.util.NamingHelper.bind(NamingHelper.java:97) at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:348) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341) ...
The contents of hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name="java:comp/env/jdbc/bmf"> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <mapping class="com.bmf.db.BMFUser" resource="com/bmf/db/BMFUser.hbm.xml"/> <mapping class="com.bmf.db.BMFWager" resource="com/bmf/db/BMFWager.hbm.xml"/> <mapping class="com.bmf.db.WagerParty" resource="com/bmf/db/WagerParty.hbm.xml"/> </session-factory> </hibernate-configuration>
I put the data source in the Tomcat server context.xml as follows:
<?xml version="1.0" encoding="UTF-8"?> <Context privileged="true" reloadable="true"> .... <Resource name="jdbc/bmf" auth="Container" type="javax.sql.DataSource" username="root" password="admin" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/bmf"/> </Context>
I read somewhere else that Tomcat creates read-only JNDI entries, but don't have clue how to get around it. I'd like to be able to do this without coding a JNDI context with a javax.sql.DataSource in it, and even then I'm not sure that it'll work.
I think I must be missing something really obvious, so apologies if that's the case.
|