Bugs item #677800, was opened at 2003-01-31 09:20 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=428708&aid=677800&group_id=40712
Category: None Group: None >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: Leonardo Quijano (lquijano) Assigned to: Nobody/Anonymous (nobody) Summary: Configuration.configure(String) bug Initial Comment: This is my code: Configuration config = new Configuration(); config.configure("/hibernate-ga.cfg.xml"); sessionFactory = config.buildSessionFactory(); When I run it, Configuration.configure() parses the correct files and get all the mappings. BUT it doesn't return the right object: public Configuration configure(String resource) throws HibernateException { InputStream stream = getConfigurationInputStream(resource); Document doc; try { doc = XMLHelper.parseInputSource( new InputSource(stream) ); } catch (Exception e) { log.error("Problem parsing configuration " + resource, e); throw new HibernateException( "Problem parsing configuration " + resource + ": " + e ); } Node sfNode = doc.getDocumentElement().getElementsByTagName("session-factory").item(0); String name = sfNode.getAttributes().getNamedItem("name").getNodeValue(); properties.setProperty(Environment.SESSION_FACTORY_NAME, name); addProperties(sfNode); Configuration ds = new Configuration(); NodeList mapElements = sfNode.getChildNodes(); for ( int j=0; j<mapElements.getLength(); j++ ) { Node mapElement = mapElements.item(j); if ( mapElement.getNodeName().equals("mapping") ) { NamedNodeMap atts = mapElement.getAttributes(); Node rsrc = atts.getNamedItem("resource"); Node file = atts.getNamedItem("file"); Node jar = atts.getNamedItem("jar"); if (rsrc!=null) { log.debug(name + "<-" + rsrc); try { ds.addResource( rsrc.getNodeValue(), Thread.currentThread().getContextClassLoader() ); } catch (MappingException me) { ds.addResource( rsrc.getNodeValue(), Environment.class.getClassLoader() ); } } else if ( jar!=null ) { log.debug(name + "<-" + jar); ds.addJar( jar.getNodeValue() ); } else { if (file==null) throw new HibernateException("<mapping> element in configuration specifies no attributes"); log.debug(name + "<-" + file); ds.addFile( file.getNodeValue() ); } } } log.info("Configured SessionFactory: " + name); log.debug("properties: " + properties); return this; } Note the creation of: Configuration ds = new Configuration(); *all* the parsed XML properties are written in this new object: ds.addResource( rsrc.getNodeValue(), Thread.currentThread().getContextClassLoader() ); or ds.addResource( rsrc.getNodeValue(), Environment.class.getClassLoader() ); for example. But the method returns "this"!! log.info("Configured SessionFactory: " + name); log.debug("properties: " + properties); return this; So I get the original, empty Configuration :/ I guess the right fix for this would be to use "this" when adding new resources and never instantiating "ds", or returning ds as a new object, right? (it's a bit confusing though, I thought that Configuration.configure() would be a void method that configures itself, rather than returning new Configurations) I guess it was a small but annoying bug... Leonardo ---------------------------------------------------------------------- >Comment By: Gavin King (oneovthafew) Date: 2003-01-31 20:10 Message: Logged In: YES user_id=384580 fixed in CVS ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=428708&aid=677800&group_id=40712 ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel