WebSphere 8 persistence.xml syntax error (expected root element) - java

Installing my web application to WebSphere Application Server 8 fails due to a syntax error in my persistence.xml. According to my IDE, there is no error. What is the actual problem?
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1"
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_1.xsd"
>
<persistence-unit name="myapp">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
</persistence-unit>
</persistence>
Excerpts from stack trace (SystemOut.log):
1:
Caused by: com.ibm.ws.metadata.MetaDataException: CWWJP0040E: The persistence.xml in application PA_Appl, module Appl-0.1.war, has a syntax error at line number: 6, column number: 2.
2:
Caused by: org.xml.sax.SAXParseException: expected root element {http://java.sun.com/xml/ns/persistence}persistence
Please comment, if you need more information.

Try this
<?xml version="1.0" ?>
<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">
<persistence-unit name="myapp">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
</persistence-unit>
</persistence>

Related

setPackagesToScan on EntityManagerFactory when Persistence.createEntityManagerFactory(

With the following code, the EntityManagerFactory's metamodel has no packages/classes.
I'm missing the parallel sessionFactory.setPackagesToScan() in LocalSessionFactoryBean.
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, hibernateReactiveProperties());
Metamodel metamodel = emf.getMetamodel();
Mutiny.SessionFactory reactiveSessionFactory = emf.unwrap(Mutiny.SessionFactory.class);
solved by adding class tag for each entity in persistence.xml
<?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="default" >
<provider>org.hibernate.reactive.provider.ReactivePersistenceProvider</provider>
<class>com.company.EntityClassName</class>
</persistence-unit>
</persistence>

EclipseLink silently ignores mapping-file from persinstence.xml

I've tried to declare converter in my orm.xml file:
orm-pg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
version="2.1">
<converter class="com.example.PgUuidConverter" auto-apply="true"/>
</entity-mappings>
persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="jpa" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=postgres-ds)</jta-data-source>
<mapping-file>META-INF/orm-pg.xml</mapping-file>
</persistence-unit>
</persistence>
Because the converter was not registered, I've added for debug another mapping-file:
<mapping-file>META-INF/orm-pg2.xml</mapping-file>
This file doesn't exist. To my surprise, the persistence unit has started without even the slightest warning in logs.
Now I'm confused because I have no idea if my converter was not registered because the orm.xml is wrong or because it was simply not loaded.
How can I debug if the mapping-file was loaded succesfully or not? Why the missing files that are referenced are ignored?
I'm deploying in Karaf Container using Aries JPA 2.5.0

http://xmlns.jcp.org/xml/ns/persistence":persistence-unit}' is expected error when using restful webservice using netbeans

I am deploying a restful webservice using jersey.I am reading this tutorial and doing instructions:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/RESTfulWebServices/RESTfulWebservices.htm
but I get this error on deploying on server .
Severe: Exception while deploying the app [PlayerServer2] :
org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 15;
Deployment descriptor file META-INF/persistence.xml in archive
[classes]. cvc-complex-type.2.4.b: The content of element
'persistence' is not complete. One of
'{"http://xmlns.jcp.org/xml/ns/persistence":persistence-unit}' is
expected.
I am using netbean 8.0.1, glassfish server 4.1, JDK 1.8.91, JPA 2.1
Edited:
persistence.xml
<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="PlayerServer2PU" transaction-type="JTA">
<jta-data-source>jdbc/playerdb2</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
Please remove the empty <properties/> tag in order for the persistence.xml file to be handled correctly.

JPA persistence.xml adding classes

I have a question regarding the class integration in the persistence xml.
Is something like this possible?
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="ranea">
<class>com.dal.pojo.*</class>
</persistence-unit>
</persistence>
I know that this does not work....but I have a rather big database structure and I would appreciate an answere how to include my pojo classes in the persistence unit easily.
If you're using Eclipse, you can right click on persistence and use "synchronize class list".

Entity manager error on the server?

Hi I have developed my java application on glassfish server with EJB 3.0 persistance. On my local machine the application was running fine and was persisting the data perfectly. However, When I deployed it on the linux server, whenever I persist any data it gives me this EJB exception error:
Caused by: Java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
And here is my persistence.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="2.0" 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">
<persistence-unit name="MyPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/security</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
</persistence>
what could possbily cause this?
PS: Im using Glassfish 3.1.43, EJB 3.0
What database are you using? I would verify that the user you have configured in the connection pool has the privilege to create tables.
I have managed to solve it finally!! The problem was in the database connection that was not set properly!! Now I have connected to the database and the data are persisted!!

Categories