Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New XSD schema in Hibernate 4

In Hibernate 4 I've found (new for me) possibility to use XSD schema instead of DTD.

<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"                
  xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

But the schema location is invalid and during initialization I've got error.

Does anybody knows what is wrong with XSD in Hibernate 4?

like image 957
smg Avatar asked Dec 20 '11 20:12

smg


2 Answers

<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
 xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping classpath://org/hibernate/hibernate-mapping-4.0.xsd" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" package="acme.foo.bar"/>

Try this, it should work better.

like image 197
jontejj Avatar answered Sep 21 '22 10:09

jontejj


Schema location is just an identifier of the place, and this place can be bound to anywhere: internet, local drive. Particularly this schema (along with hibernate-configuration-4.0.xsd) is placed inside the hibernate-core jar in the package org.hibernate. Since usually the schemaLocation and the actual location are the same, IDE will try to fetch it from where it points, but this is not our case. You can configure your IDE to find this schema in this jar so that you can use autocomplete. If we're talking about IntelliJ, then go to the settings and configure your Schemas and DTDs to include the required schema.

like image 28
Stanislav Bashkyrtsev Avatar answered Sep 23 '22 10:09

Stanislav Bashkyrtsev