I sure got off the wrong foot with Hibernate. I'm blocked by this error when I'm trying to intitialize hibernate. Here's what I'm trying to do:
Code:
...
private static final ThreadLocal threadLocal = new ThreadLocal();
...
public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
Logger.getLogger("problem").error("Error initializing Hibernate!",e);
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}
return session;
}
The problem happens where I have the try/ctach. Here it is:
Code:
24-Mar-05 17:36:26 ERROR[] [problem] Error initializing Hibernate!
org.ablogic.hibernate.SessionFactory.currentSession(SessionFactory.java:54)
net.sf.hibernate.MappingException: Error reading resource:
org/ablogic/hibernate/Accounts.hbm.xml at
net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339) at
net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1018) at
net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:974) at
net.sf.hibernate.cfg.Configuration.configure(Configuration.java:902) at
org.ablogic.hibernate.SessionFactory.currentSession(SessionFactory.java:50)
at _jsp._index__jsp._jspService(_index__jsp.java:35) at
com.caucho.jsp.JavaPage.service(JavaPage.java:61) at
com.caucho.jsp.Page.pageservice(Page.java:557) at
com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:141)
at
com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:220)
at
com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:163)
at
com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:207)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:249)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:327) at
com.caucho.util.ThreadPool.runTasks(ThreadPool.java:450) at
com.caucho.util.ThreadPool.run(ThreadPool.java:394) at
java.lang.Thread.run(Thread.java:595)Caused by:
net.sf.hibernate.MappingException: duplicate import: Accounts at
net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85) at
net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127) at
net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:222) at
net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257) at
net.sf.hibernate.cfg.Configuration.add(Configuration.java:252) at
net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
... 16 more
So apparently I attempt to import "accounts" twice... Here's my hibernate.cfg.xml:
Code:
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.username">xxx</property>
<property name="connection.url">jdbc:mysql://xxx:3306/</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">xxx</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- mapping files -->
<mapping resource="org/ablogic/hibernate/Accounts.hbm.xml"/>
<mapping resource="org/ablogic/hibernate/AccountAttributes.hbm.xml"/>
<mapping resource="org/ablogic/hibernate/AccountPrivileges.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Any idea what could be causing this error?