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: problem passing inputstrem to hibernate configuration
PostPosted: Thu Nov 23, 2006 4:46 am 
Newbie

Joined: Thu Nov 23, 2006 4:20 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 7:50 am 
Newbie

Joined: Thu Nov 23, 2006 4:20 am
Posts: 2
problem solved. need to cal is.reset(); before addInputStream(); :)


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.