I had Hibernate working great until I need to add a second database to my application. Originally, I used the following to load my config:
_hibernateSessionFactory = new Configuration().configure().buildSessionFactory();
I had my hibernate.cfg.xml located in the root of my web application classpath. I then had to give it specific names for multiple configs. So, I named my two configuration files and placed them in the root of the classpath. So I tried the following:
_hibernateSessionFactory = new Configuration().configure("event.cfg.xml" ).buildSessionFactory();
Hibernate threw an exception saying that it could find the configuration. Just to make sure it was in the classpath correctly, I did the following:
ClassLoader classLoader = this.getClass().getClassLoader();
URL configURL = classLoader.getResource("event.cfg.xml");
_hibernateSessionFactory = new Configuration().configure(configURL).buildSessionFactory();
This loaded the configuration file without problem, except I got a new exception:
net.sf.hibernate.MappingException: Error reading resource: ai/event/calendar/objects/Event.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:294)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:944)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:896)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:847)
at ai.event.calendar.EventCalendarDatabase.<init>(EventCalendarDatabase.java:33)
at ai.event.calendar.EventCalendarDatabase.getInstance(EventCalendarDatabase.java:42)
at ai.event.calendar.servlets.UpcomingEventsServlet.doGet(UpcomingEventsServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:479)
Caused by: net.sf.hibernate.MappingException: duplicate import: Event
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:68)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:123)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:207)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1167)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:245)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:268)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:291)
This behavior seems weird to me since I could get Hibernate to find my configuration file by specifying the URL and it couldn't find it otherwise. Now, I'm completely lost with the new error. Anyone have any suggestions?
|