hi there,
i am stuggeling with a problem trying to configure hibernate by passing an inputstream instead of an url containing the hibernate.cfg.xml because this resource is located in a jar file.
reading the resource is no problem:
Code:
Configuration config = new Configuration();
InputStream is = Thread.currentThread().getContextClassLoader().
getResourceAsStream("hibernate/hibernate.cfg.xml");
but when i try to pass it to hibernate like this:
Code:
config.addInputStream(is);
hibernate then throws an exception:
Code:
org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:469)
at net.hibernate.PersistenceManager.<init>(PersistenceManager.java:62)
......
Caused by: org.dom4j.DocumentException: Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:460)
... 106 more
but the xml code in the inputstream looks fine to me:
Code:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.datasource">java:/comp/env/jdbc/userdb</property> <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> <property name="show_sql">true</property> <!-- Mapping files --> <mapping resource="/hibernate/mapping/reg_users.hbm.xml"/> <mapping resource="/hibernate/mapping/user_online.hbm.xml"/> <mapping resource="/hibernate/mapping/image_comments.hbm.xml"/> <mapping resource="/hibernate/mapping/userimages.hbm.xml"/> <mapping resource="/hibernate/mapping/profile_visits.hbm.xml"/> <mapping resource="/hibernate/mapping/smileys.hbm.xml"/> </session-factory> </hibernate-configuration>
any idea what am i doing wrong here?
best regards and thank in advance for any help,
nicolas