JPA - disable persistence.xml validation

I am taking the first steps with JPA (Hibernate). The general idea is to connect to an outdated database to perform complex queries. I think hibernation is a great companion for this task, but ...

... for starters, I created one configuration file bean, persistence.xml and hibernate.cfg.xml and some lines of code in the main method, starting with:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo");

It reads the persistence.xml file, but since I am disconnected from the Internet, it cannot read the schema file (xsd) to check persistence.xml and complains about exceptions. (And I do not have a local copy of persistence.xsd in this environment). I tried to remove the schemalocation attribute, but that did not help. No grammar, no JPA !?

Is there a way / trick / workaround to disable document validation, at least for parsing persistence.xml?

+2
source share
1 answer

Extracted from JPA specification

The container / media provider (Hibernate) should check the persistence.xml file on the persistence_1_0.xsd schema and report any validation errors

...

Save configuration files must specify a save scheme using persistence namespace

 http://java.sun.com/xml/ns/persistence

And specify the version of the schema using the version element as shown below

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
             http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">

The item shown above is valid for JPA 1.0 Upgrade to 2.0 if you are using JPA 2.0

+3
source

Source: https://habr.com/ru/post/1792880/


All Articles