有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JPA禁用持久性验证。xml

我正在使用JPA(Hibernate)迈出第一步。总体思路是连接到遗留数据库以执行复杂的查询。我认为,hibernate是这个任务的一个很好的伙伴,但是

。。。首先,我创建了一个bean,持久性。xml和hibernate。cfg。主方法中的xml配置文件和一些代码行,从以下内容开始:

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

它读取持久性。xml文件但是,因为我与internet断开连接,它无法读取模式文件(xsd)来验证持久性。xml,但有例外。(我在那个环境中没有persistence.xsd的本地副本)。我尝试删除schemalocation属性,但没有帮助。没有语法,就没有JPA

是否有一种方法/技巧/解决方法可以至少在解析持久性时禁用文档验证。xml


共 (1) 个答案

  1. # 1 楼答案

    摘自JPA规范

    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">
    

    如果您使用的是JPA2.0,则上面显示的元素对JPA1.0有效