-->
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.  [ 2 posts ] 
Author Message
 Post subject: read hibernate-configuration-3.0.dtd from jar file
PostPosted: Thu Nov 16, 2006 10:47 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
Hello,

I am using the org.hibernate.cfg.Configuration class to read in an xml file stored as a org.w3c.dom.document object with the config method.

My code looks like this:

InputStream inps = getClass().getResourceAsStream("/hibernate.cfg.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
document = parser.parse(inps);
Configuration config = new Configuration();
config.configure(document);
sessionFactory = config.buildSessionFactory();

The problem is that when the parser.parse method is called, the hibernate-configuration-3.0.dtd is obtained from the internet instead of the jar file. This is a problem because the http request can't get past our firewall. It there a way to force it to use the DTD from the jar file?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 4:27 pm 
Newbie

Joined: Wed Sep 14, 2005 12:17 pm
Posts: 13
You want to provide a DTD Entity Resolver, like so:

Code:
InputStream inps = getClass().getResourceAsStream("/hibernate.cfg.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();

parser.setEntityResolver(new MyEntityResolver());

document = parser.parse(inps);
Configuration config = new Configuration();
config.configure(document);
sessionFactory = config.buildSessionFactory();


See the javax.xml.parser package for the EntityResolver implementation.

You can also try to plug in Hibernate's Entity Resolver (although I haven't tried this myself):

Code:
parser.setEntityResolver(new DTDEntityResolver());


BC


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.