Resolves offline could not parse Configuration:hibernate.cfg.xml error

Source: Internet
Author: User
Tags xml parser

Use Hibernate tool offline to generate reverse engineering, after configuration profile is completed, the configuration file is generated, org.hibernate.HibernateException:Could not parse configuration is reported: Error

Reason: is not read the local DTD constraints, and then must be loaded each time the network, the specific reasons do not understand, because the net of this aspect of the solution is relatively vague, it should be a small range of issues, the sense is that JDK and tools require version inconsistency, resulting in some plug-ins are not properly installed, parsing problems

Workaround (In the same way you can resolve the problem that the mapping file is not resolved)

: First confirm that the format content of the Cfg.xml file is correct

Mode 1. Connect TO Network!!!!!

(If the network is bad, parsing is unsuccessful)

Mode 2. Use the local DTD: (Hibernate design is first read locally, but may be due to plug-in problems, can not read local, directly load the network)

(Fast, improve efficiency)

<! DOCTYPE hibernate-configuration  SYSTEM "Classpath://org/hibernate/hibernate-configuration-3.0.dtd" ><!- This is the most desirable way to replace--

(Before using, please confirm whether to import the hibernate package)

------------------------------------------------------get some crap.

Before the test, the computer connected to the network, when modifying the local path, just modify the "HTTP://WWW.HIBERNATE.ORG/DTD/HIBERNATE-CONFIGURATION-3.0.DTD" this part of the content, as long as the network actually how to modify it does not affect, Because there is a public ID in front of the impact, there should not be used in the normal path format, according to XML format URI format, because the XML parser first will be a mechanism to find a common DTD name, found, then as a standard, if not found, and then go to the DTD location to find, So you just need to modify some of the content, but you need a path write pair, there are many ways to look for local XML constraints.

The first in the Eclipse settings, Window/preferences/xml/xml catalog/settings, locate the-//hibernate/hibernate Configuration DTD 3.0//en Click, The details below will appear with their URI: Copy and replace the XML DTD

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE hibernate-configuration public                                "-//hibernate/hibernate configuration DTD 3.0//en"                                "File:/c:/program files/eclipse/. /.. /xx/.eclipse/org.eclipse.platform_4.5.1_1709980481_win32_win32_x86_64/plugins/org.hibernate.eclipse.mapper_ 4.0.1.final-v20150324-2307-b95/dtd/hibernate-configuration-3.0.dtd "> <!--this is found in the XML settings, each computer's path is different, to copy its own path , the path is too long and is not recommended--

  

Second, in fact, in the HIBERNATE-CORE-XX core jar package has built-in DTD file (both the configuration file and the mapping file), under the org/hibernate/package, because the package is already, so you can also use the classpath path

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE hibernate-configuration public                                "-//hibernate/hibernate configuration DTD 3.0//en"                                "classpath://org/ Hibernate/hibernate-configuration-3.0.dtd "> <!--this is to use the Classpath path configuration, adapted to each machine, recommended, but using the following method, the resolution will be a bit faster--

  

Although the above can solve the problem, it is recommended to use the direct local constraints of the system, regardless of the network without the network directly read local constraints, so much faster

<! DOCTYPE hibernate-configuration  SYSTEM                                "File:/c:/program files/eclipse/. /.. /xx/.eclipse/org.eclipse.platform_4.5.1_1709980481_win32_win32_x86_64/plugins/org.hibernate.eclipse.mapper_ 4.0.1.final-v20150324-2307-b95/dtd/hibernate-configuration-3.0.dtd "> <!--this is found in the XML settings, the path length is not recommended--  <! DOCTYPE hibernate-configuration  SYSTEM "Classpath://org/hibernate/hibernate-configuration-3.0.dtd" ><!- -classpath configuration-, short path, adapt to different machines, fast, recommended to use this configuration,

  

  

(You can also do this if there is a problem with the mapping file)

<! DOCTYPE hibernate-mapping SYSTEM "CLASSPATH://ORG/HIBERNATE/HIBERNATE-MAPPING-3.0.DTD" >

  

Knowledge about DTDs (mainly two types of references)

To define the syntax for an external DTD:

<! DOCTYPE root element Name System "URI for external DTD file" > (System indicates that the DTD file is private.) Quotation marks must not be less)

<?xml version= "1.0" encoding= "UTF-8" standalone= "yes"?>

<?xml-stylesheet href= "Simple1.css" type= "Text/css"?>

<!--external DTD---

<! DOCTYPE poem SYSTEM "Poem.dtd" >

<poem>

<title> Quiet Night thinking </title>

<author> Li Bai </author>

<line> Moon light,</line> before Bed

<line> suspected ground Frost .</line>

<line> Jutou hope the Moon,</line>

<line> bow to think hometown .</line>

<commet> Li Bai is the greatest poet in China! </commet>

</poem>

-----------------------------the POEM.DTD content in the same directory as follows:

<?xml version= "1.0" encoding= "UTF-8"?>

<! ELEMENT Poem (Title,author,line+,commet) >

<! ELEMENT title (#PCDATA) >

<! ELEMENT author (#PCDATA) >

<! ELEMENT Line (#PCDATA) >

<! ELEMENT Commet (#PCDATA) >

What if you want to refer to a common DTD document?

<! DOCTYPE root element name public "DTD name" "URI of External DTD file" > (publicly means that the DTD file is common, note that there is more than one DTD name after the Quotation marks must not be less)

Here is the DTD for Taglib:

<! DOCTYPE taglib Public "-//sun Microsystems, Inc.//dtd JSP Tag Library 1.2//en"

"Http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd" >

Analyze this external DTD declaration:

1, the key word doctype,public.

2, root element name: Taglib. So each tag library definition file is taglib as the root element, otherwise it will not be validated.

3, the purple word "-//sun Microsystems, Inc.//dtd JSP Tag Library 1.2//en", this is the name of the public DTD. The name of this thing is somewhat fastidious. First it begins with a "-", indicating that the DTD is not a standard organization. (if it is approved by the ISO standardization Organization, start with "ISO", if it is not approved by the ISO standardization Organization, start with "+". )。 Then there is the double slash "//" followed by the name of the DTD owner, and it is clear that the DTD is fixed by sun. followed by a double slash "//" followed by the document type described by the DTD, you can see that this DTD describes the format of the JSP tag Library version 1.2. Followed by the "//" and ISO 639 language identifiers.

4, the green word "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd", indicating the location of this DTD.

Question: Is the XML parser going to java.sun.com to find the DTD? The answer is no, the XML parser first looks for the name of the public DTD in a mechanism, finds it, and, if not, finds it in the DTD position.

Knowledge about URI URLs

Uri:uniform Resource Identifier, Uniform Resource Identifier;

Url:uniform Resource Locator, Uniform Resource Locator;

Urn:uniform Resource name, Uniform resource names.

Where Url,urn is a subset of URIs.

The basic form of an address on the web is a URI, which represents the Uniform Resource identifier. There are two kinds of forms:

URL: The most common form of URIs today is ubiquitous URLs or uniform resource locators.

An updated form of Urn:url, the Uniform Resource name (URN, Uniform Resource name) is not dependent on the location, and it is possible to reduce the number of failed connections. But its popularity will take time, because it requires more sophisticated software support.

A URI is a simple string that identifies a resource in a uniform (standardized) way.

URIs are generally made up of three parts:

1. Access the resource naming mechanism.

2. Host name of the resource to be stored.

3. The name of the resource itself, represented by the path.

Typically, this string begins with the scheme (the identifier of the namespace that names the URI-a set of related names), with the following syntax:

[Scheme:] Scheme-specific-part

The URI begins with a scheme and a colon. Scheme starts with uppercase/lowercase letters, followed by empty or followed by more uppercase/lowercase letters, numbers, plus signs, minus and dot numbers. The colon separates scheme from Scheme-specific-part, and the syntax and semantics of scheme-specific-part (meaning) are determined by the namespace of the URI. As in the following example:

Http://www.cnn.com, where HTTP is scheme,//www.cnn.com is Scheme-specific-part, and its scheme is separated from Scheme-specific-part by a colon.

URIs have absolute and relative points, and absolute URIs refer to the URIs that begin with scheme (followed by a colon). The http://www.cnn.com mentioned above is an example of an absolute URI, and other examples are mailto:[email protected], News:comp.lang.java.help, and XYZ://whatever. You can think of an absolute URI as referencing a resource in a way that is not dependent on the environment in which the identifier appears. If you use the file system as an analogy, an absolute URI is similar to the path of a file starting from the root directory.

Unlike an absolute URI, a relative URI is not a URI that begins with scheme (followed by a colon). An example of this is articles/articles.html. You can think of a relative URI as referencing a resource in a way that relies on the environment in which the identifier appears. If the file system is used as an analogy, the relative URI is similar to the file path starting from the current directory.

The URL is the abbreviation for Uniform Resource location, translated as "Uniform Resource Locator." In layman's words, URLs are strings used on the Internet to describe information resources, mainly used in various WWW client programs and server programs, especially the famous mosaic. URLs can be used in a unified format to describe various information resources, including files, server addresses and directories.

The format of the URL consists of the following three parts:

The first part is the agreement (or service mode);

The second part is the host IP address (and sometimes the port number) where the resource is stored;

The third part is the specific address of the host resource. , such as directory and file name.

The first and second sections are separated by a "://" Symbol, and the second and third sections are separated by a "/" symbol. The first part and the second part are indispensable, and the third part can be omitted sometimes.

At present, the biggest disadvantage is that when the information resource storage location changes, the URL must be changed accordingly. So people are looking at new ways to represent information resources, such as URIs (Universal Resource Identifier), which are "Generic resource Identifiers" (see RFC 1630), URN (Uniform Resource name), and Uniform Resource name and URC (Uniform Resource citation) are "Uniform resource references" and so on.

The URI is still in the midst of further research. The direction of research is to make up for the current shortcomings of URLs.

Resources

Http://www.blogjava.net/flysky19/articles/93379.html

http://my.oschina.net/aiguozhe/blog/40592

Http://stackoverflow.com/questions/4301294/cant-parse-hibernate-cfg-xml-while-offline

Resolves offline could not parse Configuration:hibernate.cfg.xml error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.