0

i faced with error like this :

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://xmlns.jcp.org/xml/ns/persistence", local:"persistence"). Expected elements are <{http://java.sun.com/xml/ns/persistence}persistence>
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:740)
        at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:262)

I'm try build a simple osgi jpa 2.1 module, which will run on Glassfish 4.1 and use Postgres 9.4. JDBC resources on GF was created and it work fine (i mean "ping" button), as well as was write a persistence.xml file on META-INF dir :

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="something" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myjdbc</jta-data-source>
        <properties>
            <property name="javax.persistence.schema-genaration" value="drop-and-create"/>
        </properties>
    </persistence-unit>
</persistence>

And most interesting is that - if i replace jpa 2.1 schema to jpa 2.0 it will work fine, but only can't create a table from entity class.

So, how to solve this problem and use JPA 2.1 xml schema.

Add.information :

News entity is here :

@Entity
public class News {

    @Id
    @GeneratedValue
    private Long ID;
    private String title;
    private String content;
    private Long views;

    // getters and setters.... default non-arg constructor was omitted

My pom.xml file :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>myTestProject</artifactId>
        <groupId>com.myTestProject</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.myTestProject.module.domain</groupId>
    <artifactId>module.domain</artifactId>
    <packaging>bundle</packaging>

    <name>module.domain</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>com.myTestProject.module.domain.*</Export-Package>
                        <Import-Package>javax.persistence.*, org.osgi.framework</Import-Package>
                        <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                        <Bundle-Activator>com.myTestProject.module.domain.Activator</Bundle-Activator>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.5.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
Benjamin
  • 531
  • 2
  • 6
  • 18
  • It is not clear from your question if the exception you are getting is during table creation or when you are performing other operations, can you clarify please? – KayDK May 15 '15 at 10:43
  • I actually get this exact same thing when deploying within an OSGi bundle and trying to use the 2.1 namespace in doing basically the same thing as above. Was there ever any solution? This is just when doing a deployment and before the framework even recognizes the bundle as being a JPA bundle (in the initial parsing). – Robert B. Weeks Sep 09 '15 at 17:04
  • Just in case anyone else sees this as well - this is caused because the jpa bridge in GlassFish (osgi-jpa.jar) was not updated to handle the 2.1 schema. You can see/update this in the source glassfish~svn/trunk/fighterfish/module/osgi-jpa. – Robert B. Weeks Sep 14 '15 at 19:11

0 Answers0