-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: reading hibernate.cfg.xml with DocumentBuilderFactory
PostPosted: Thu Feb 24, 2005 9:29 am 
Newbie

Joined: Wed Jan 05, 2005 5:30 am
Posts: 14
I am trying to read in the hibernate.cfg.xml file using DocumentBuilderFactory. But it times out. It has problem with the following

Code:
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>



Removing this makes it work, but then hibernate stalls :)

Hope you can help

regards Middy

My code
Code:
rivate void modifySqlServerPath(){
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setIgnoringComments(true);
      factory.setIgnoringElementContentWhitespace(true);
      try {
         DocumentBuilder builder = factory.newDocumentBuilder();
      
         
         hibernateCFG = builder.parse(new File(hibernateCFGPath));
         NodeList e = hibernateCFG.getElementsByTagName("property");
         
         Node node = e.item(1);
         node.getTextContent();
         
         //Format :jdbc:mysql://192.168.12.50/werkstette
         node.setTextContent("jdbc:mysql://" + sqlServerPath + ":"+ sqlServerPort + "/werkstette");
         
         DOMSource source = new DOMSource(hibernateCFG);
         StreamResult result = new StreamResult(new FileOutputStream(
               hibernateCFGPath));
         
         TransformerFactory transFactory = TransformerFactory.newInstance();
         Transformer transformer;
         
         transformer = transFactory.newTransformer();
         transformer.transform(source, result);
         
      } catch (SAXException sxe) {
         // Error generated during parsing
         Exception x = sxe;
         if (sxe.getException() != null)
            x = sxe.getException();
         x.printStackTrace();
         
      } catch (ParserConfigurationException pce) {
         // Parser with specified options can't be built
         pce.printStackTrace();
         
      } catch (IOException ioe) {
         // I/O error
         ioe.printStackTrace();
      } catch (TransformerConfigurationException e1) {
         
         e1.printStackTrace();
      } catch (TransformerException e2) {
         
         e2.printStackTrace();
      }   
      
   }



Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 11:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Hibernate uses a custom EntityResolver registered with the SAXReader in order to resolve the DTD locally.

You should just have to add:
Code:

    DocumentBuilder builder = factory.newDocumentBuilder();
    builder.setEntityResolver( new DTDEntityResolver() );
    hibernateCFG = builder.parse(new File(hibernateCFGPath));


Where DTDEntityResolver is net.sf.hibernate.util.DTDEntityResolver


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 5:19 am 
Newbie

Joined: Wed Jan 05, 2005 5:30 am
Posts: 14
great thanks, that solved it :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.