Can't parse hibernate.cfg.xml while offline

前端 未结 13 1689
死守一世寂寞
死守一世寂寞 2020-11-29 08:13

Whenever I\'m disconnected from the internet, I get the following exception:

org.hibernate.HibernateException: Could not parse configuration: com/mashlife/re         


        
相关标签:
13条回答
  • 2020-11-29 08:51

    in my situation: JBoss AS 7

    I check:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    

    and exclude dom4j in pom.xml

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.9-SNAPSHOT</version>
            <exclusions>
                ...........
                <exclusion>
                    <artifactId>dom4j</artifactId>
                    <groupId>dom4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    
    0 讨论(0)
  • 2020-11-29 08:51

    I have used following method to skip the validation of Doctype in the Configuration file

    Code:-

    public static Document parseConfiguration(String resourcePath) throws Exception {
    
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    
    
    
            factory.setValidating(false); 
    
            DocumentBuilder builder = factory.newDocumentBuilder();
    
             File f=new File(resourcePath);
    
    
            FileInputStream fs=new FileInputStream(f);
    
            Document dtd = builder.parse(fs);
    
            return dtd;
    
            } 
    
    
    
    public static void main(String[] args)
     { 
    
       Document dtd=null;
    
            try {
                dtd = parseConfiguration("src/hibernate.cfg.xml");
    
            } catch (Exception e) {
    
                e.printStackTrace();
            }
    
            SessionFactory  factory=new AnnotationConfiguration()  
             .configure(dtd).buildSessionFactory(); 
    /*
    Now this code worked for me 
    You just have to use annotation instead of hbm.xml file because I was not able to skip the validation of mapping file as it is written inside the cfg.xml file
    Reply if you got some other answer to run hibernate application in offline */
    
    0 讨论(0)
  • 2020-11-29 08:55

    I had this problem too. My DOCTYPE was:

    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    

    It should be:

    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    

    Can you see the difference? The first URI has NOT www and the second URI has www

    So, the www in the URI must be declared in the configuration file and in all the mapping files.

    It is not your case (cause I can see you have the http://www... URI), but it may help somebody.

    Regards.

    0 讨论(0)
  • 2020-11-29 08:59
    • Another Way is You should download DTD file and set the file path. and also set the dtd file location in java Build path (eclipse).

    Hibernate-configuration

    Orignal DTD

    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    

    Corrected DTD

    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://localhost:8080/YourProject/DTDLocation/hibernate-configuration-3.0.dtd">
    

    Hibernate-mapping

    Orignal DTD

    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    

    Corrected DTD

    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://localhost:8080/YourProject/DTDLocation/hibernate-mapping-3.0.dtd">
    
    0 讨论(0)
  • 2020-11-29 09:00

    Alberto Daniel actually is right, indeed adding the "www." fixed for me the problem.

    I guess, since the hibernate-core.jar file contains the dtd files, exactly the location http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd is treated somehow specially by the XML parser, so that the dtd from the jar file is used. I did not verify this, but it may be an explanation. However: Thank you Alberto!

    Regards.

    0 讨论(0)
  • 2020-11-29 09:02

    Just check this site https://forum.hibernate.org/viewtopic.php?f=1&t=943281&start=0

    Hope that it will solve your problem.

    0 讨论(0)
提交回复
热议问题