Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA - disable validation of persistence.xml

I'm taking my first steps with JPA (Hibernate). The overall idea is to connect to a legacy database to do complex queries. I think, hibernate is a great companion for this task, but...

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

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

It reads the persistence.xml file but, because I'm disconnected from the internet, it can't read the schema file (xsd) to validate persistence.xml and complains with exceptions. (And I don't have a local copy of persistence.xsd in that environment). I tried with removing the schemalocation attribute, but that didn't help. No grammar, no JPA!?

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

like image 879
Andreas Dolk Avatar asked Dec 16 '25 19:12

Andreas Dolk


1 Answers

Extracted from JPA specification

The container/presistence provider (Hibernate) must validate the persistence.xml file against the persistence_1_0.xsd schema and report any validation errors

...

Persistence configuration files must indicate the persistence schema by using the persistence namespace

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

And indicate the version of the schema by 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 element shown above is valid for JPA 1.0 Update to 2.0 if you are using JPA 2.0

like image 149
Arthur Ronald Avatar answered Dec 19 '25 11:12

Arthur Ronald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!