I use the following to create a configuration that's similar to the original configuration object - let me know if you find a better way. Also, this is broken for me on hibernate 2.1.6 - anybody have an idea why it would process most of my mapping files, then get the exception shown below the code? I checked the jar used in the EAR and the mapping file is in there.
Wayne
------------------
Code:
private static Configuration hCfg = null;
public static Configuration getNewConfig()
{
Configuration newCfg = null;
Properties props = Environment.getProperties();
Iterator it = props.keySet().iterator();
System.err.println("Properties:");
while (it.hasNext())
{
Object obj = (Object) it.next();
System.err.println(obj.toString() + ": " + props.get(obj).toString());
}
try
{
Session foo = getSession();
newCfg = new Configuration();
newCfg.addProperties(props);
Map allClasses = aSessionFactory.getAllClassMetadata();
Iterator acIt = allClasses.keySet().iterator();
while (acIt.hasNext())
{
Class aMappedClass = (Class) acIt.next();
System.err.println("About to add class to config: " + aMappedClass.getName());
newCfg.addClass(aMappedClass);
}
SessionFactory sf = newCfg.buildSessionFactory();
}
catch (HibernateException e)
{
e.printStackTrace();
}
catch (NamingException e)
{
e.printStackTrace();
}
return newCfg;
}
------------
2004-10-13 09:15:12,153 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/ormapping/Chem_link.hbm.xml
2004-10-13 09:15:12,169 INFO [net.sf.hibernate.cfg.Binder] Mapping class: org.pdb.ormapping.Chem_link -> chem_link
2004-10-13 09:15:12,169 INFO [STDOUT] About to add class to config: org.pdb.ormapping.Em_icos_virus_shells
2004-10-13 09:15:12,169 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/ormapping/Em_icos_virus_shells.hbm.xml
2004-10-13 09:15:12,169 INFO [net.sf.hibernate.cfg.Binder] Mapping class: org.pdb.ormapping.Em_icos_virus_shells -> em_icos_virus_shells
2004-10-13 09:15:12,169 INFO [STDOUT] About to add class to config: org.pdb.derived.CathNode
2004-10-13 09:15:12,184 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/derived/CathNode.hbm.xml
2004-10-13 09:15:12,184 INFO [net.sf.hibernate.cfg.Binder] Mapping class: org.pdb.derived.CathNode -> cath_node
2004-10-13 09:15:12,184 INFO [STDOUT] About to add class to config: org.pdb.derived.CathProteinDomainFramgent
2004-10-13 09:15:12,184 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/derived/CathProteinDomainFramgent.hbm.xml
2004-10-13 09:15:12,200 INFO [STDOUT]
net.sf.hibernate.MappingException: Resource: org/pdb/derived/CathProteinDomainFramgent.hbm.xml not found
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:352)
at org.pdb.ormapping.util.HibernateUtils.getNewConfig(HibernateUtils.java:53)
at org.pdb.ormapping.util.HibernateUtils.getHibernateConfig(HibernateUtils.java:72)
at org.pdb.util.db.loaders.LoadMetadata.processDerivedTable(LoadMetadata.java:387)
at org.pdb.util.db.loaders.LoadMetadata.generateMetadata(LoadMetadata.java:704)
at org.pdb.util.db.loaders.LoadMetadata.preDatabaseLoad(LoadMetadata.java:72)
at org.pdb.util.db.loaders.DataLoaderUtil.runUpdate(DataLoaderUtil.java:160)
at org.pdb.util.db.loaders.DataLoaderUtil.run(DataLoaderUtil.java:93)
at java.lang.Thread.run(Thread.java:534)