Failed to validate XML

#1
[ObjectDB 2.6.7_05] javax.persistence.PersistenceException
Failed to validate xml file /{erased-by-me}/tiro/lib-core/build/resources/test/META-INF/persistence.xml:
(error 211)
at com.objectdb.jpa.Provider.createEntityManagerFactory(Provider.java:88)
at com.objectdb.jpa.Provider.createEntityManagerFactory(Provider.java:32)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.tiro.entities.UsersGroupsRolesSecurityTest.setUp(UsersGroupsRolesSecurityTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: com.objectdb.o.UserException: Failed to validate xml file /{erased-by-me}/tiro/lib-core/build/resources/test/META-INF/persistence.xml:
at com.objectdb.o.MSG.d(MSG.java:75)
at com.objectdb.o.XMD.n(XMD.java:224)
at com.objectdb.o.XMD.k(XMD.java:155)
at com.objectdb.o.UNM$z._e(UNM.java:182)
at com.objectdb.o.UNM$z.<init>(UNM.java:169)
at com.objectdb.o.UNM.x(UNM.java:105)
at com.objectdb.o.UNM.w(UNM.java:75)
at com.objectdb.jpa.Provider.createEntityManagerFactory(Provider.java:58)
... 32 more
Caused by: java.lang.NullPointerException
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:670)
at com.objectdb.o.XMD.n(XMD.java:206)
... 38 more

 

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Schemas: http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/index.html -->
<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_2_0.xsd"
        version="2.0">

    <!-- Unit testing persistence unit. -->
    <persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
        <provider>com.objectdb.jpa.Provider</provider>
        <class>com.tiro.entities.Role</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="testing.tmp;drop"/>
            <property name="javax.persistence.jdbc.user" value="admin"/>
            <property name="javax.persistence.jdbc.password" value="admin"/>
        </properties>
    </persistence-unit>
</persistence>

 

Unit test:

@RunWith(JUnit4.class)
public class UsersGroupsRolesSecurityTest {
  private static final String ALL_MODEL_PACKAGES = User.class.getPackage().getName() + ".*";

  private EntityManager em;

  @Before
  public void setUp() throws Exception {
    // register all entities
    com.objectdb.Enhancer.enhance(ALL_MODEL_PACKAGES);

    final EntityManagerFactory factory = Persistence.createEntityManagerFactory("objectdb:testing.tmp;drop");
    em = factory.createEntityManager();

    // create minimalistic set of entities in tables for good testing

  }

  @After
  public void tearDown() throws Exception {
    if (null != em) {
      em.close();
    }
  }

  /** Create database schema from entities. */
  @Test
  public void testCreateSchema() throws Exception {

  }
}

Build.gradle

apply plugin: 'java'

// we will use lambda
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'

repositories {
  maven { url "http://m2.objectdb.com" }
}

dependencies {
  compile 'org.slf4j:slf4j-api:+'
  compile 'javax:javaee-api:+'

  testCompile 'junit:junit:+'
  testCompile 'com.objectdb:objectdb:+'
}

 

How to fix this?!

 

I see possible solutions:

- validate JAR file and be 100% sure that inside it included one of following resources: "javax/persistence/persistence_2_1.xsd", "javax/persistence/persistence_2_0.xsd", "javax/persistence/persistence_1_0.xsd" (maybe should be provided additional JAR file with those resources?!)

- getClassLoader().getResource(...) failing... maybe should be included some kind of option for skipping this?!

#2

Found solution:

download all three schemas from page - http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/index.html

In project do modifications:

  • in resources folder create package "javax.persistence"
  • place into package all three downloaded schemas 

Now project will work without any problem. getResource() will find resources during the call.

#3

Thank you for this report. objectdb.jar already includes these resources.

Are you using objectdb.jar or objectdb-jee.jar?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#4

gradle notation : testCompile 'com.objectdb:objectdb:+'

I believe that force project to use latest version of the published library. 

project uses: com.objectdb:objectdb:2.6.7_05 version

#5

Could you please try version 2.6.7_06 (available now) without your workaround?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login