Doctype of Basic O/R Mapping in Hibernate by R4R Team

In the hibernate mapping we know that all xml mapping should declare the doctype. We need to remember that the actual DTD can be found at the URL above, in the directoyr hibernate-x.x.x/scr/org/hibernate or in hibernate3.jar. When we run the hibernate programe then always hibernate look for the DTD in its class path first. When we have the experience lookups of the DTD using an Internet connection then we can check the DTD declaration against the contents of the class path.


When we build the hibernate application which can be web or console aplication that have to check in the first attempt to resolve the DTD in its classpath. Fist it register a custom org.xml.sax.EntityResolver implementation with the SAXReader. This is used to read the xml files. This custom EntityResolver recognizes two different systemId namespaces which are given below:

1. Hibernate namespace is recoginzed whenever the resolver encouters a systemId starting with The resolver attempts to resolve these entities via the classloader which loaded the Hibernate class.

2. user namespace is recognized whenever the resolver encounters a systemId using a classpath://URL protocol. The resolver will attempt to resolve these entities via (1) the current thread context classloader and (2) the classloader which loaded Hibernate classes.

Which can be understand by the following code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "" [
    <!ENTITY types SYSTEM "classpath://your/domain/types.xml">

<hibernate-mapping package="your.domain">
    <class name="MyEntity">
        <id name="id" type="my-custom-id-type">

Where types.xml is a resource in the your.domain package and contains a custom typedef.
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!