I'm having some trouble getting this working...If the mappings aren't in hibernate.cfg.xml, it doesn't seem to find them even after I load the separate mapping file. I don't know if I'm doing this the right way, but I want to get this figured out. Can anyone tell me why the mappings in mappings.cfg.xml aren't really being included in the session factory? When I try to run a simple query I get unexpected token errors that aren't there when I put the mappings in hibernate.cfg.xml.
hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="java:comp/env/hibernate/SessionFactory">
<!-- properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@192.168.1.61:1521:DB</property>
<property name="hibernate.connection.username">login</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<mapping resource="_Dummy.hbm.xml"/>
</session-factory>
</hibernate-configuration>
It balks if there's no dummy mapping...Any way to avoid that?
mappings.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="java:comp/env/hibernate/SessionFactory">
<!-- mapping files -->
<mapping resource="Content.hbm.xml"/>
...
<mapping resource="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Here's the session initialization from the servlet listener class:
Code:
public SessionFactory createSessionFactory() throws Exception {
SessionFactory sessions = null;
Configuration cfg = null;
try {
log.info("Loading hibernate.cfg.xml from classpath.");
cfg = new Configuration().configure();
log.info( "Adding mappings to Hibernate configuration..." );
mappings = getClass().getClassLoader().getResourceAsStream( "mappings.cfg.xml" );
cfg.addInputStream( mappings );
sessions = cfg.buildSessionFactory();
} catch (Exception e) {
log.error("Could not initialize webapp:", e);
}
return sessions;
}
Do I need to do my own parsing like in the thread posting above? I'm kinda boggled by all this.