For a project I'm using MOXy in order to (un)marshal XML files, and I have some problem with it that I didn't have with the standard jaxb engine.
But here, I'll focus on a single issue: I want to disable the internal logging of eclipselink.
For example, I have logging like:
[Fatal Error] input.xml:4:1: The end-tag for element type "name" must end with a '>' delimiter.
And I just don't want it. I tried many things but no luck. Maybe it's just that I'm not used to this all logging system and persistence thing, but I'd love some help.
I've followed:
http://eclipse.org/eclipselink/documentation/2.5/jpa/extensions/p_logging_level.htm and https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
But I'm not sure how this whole persistence.xml thing work. I'm working on a standard Java Project, no web-app or anything, just a standard project. I tried to create in my resource directory :
META-INF/persistence.xml
<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="test">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.logging.level" value="OFF" />
</properties>
</persistence-unit>
</persistence>
But nothing changed. I tried to pass -Declipselink.logging.level=OFF, but no luck either. Do someone know what I'm doing wrong?
Thanks.
The logging you wish to disable is SAX Parser logging. The odds are that at the moment there is no way to disable this logging from within MOXy. I have filed a bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=461829
Related
I have a little Java-project for my school. I use Eclipse Neon with JPA Diagram Editor and JavaFX. The problem -> when I set up the connection to the database, everything worked well (structure: project -> META-INF -> persistence.xml, generated through JPA). I didn't change the folder name or something in the persistence.xml, I only worked in the Main-class and added a new DAO-class. And now I get this error-message and don't understand why.
<?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="Kursverwaltung" transaction-type="RESOURCE_LOCAL">
<class>model.Course</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:#localhost:1521:xe"/>
<property name="javax.persistence.jdbc.user" value="*right username*"/>
<property name="javax.persistence.jdbc.password" value="*right password*"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
so how can the project don't find a file, which worked and I didn't changed a the folder or file name... or anything which could have something to do with the path? I only found answers that the path is wrong, but the structure was create through the JPA and worked, so I think that shouldn't be the problem.
Thanks for helping
and sorry if the grammar is not so good.
I came across this post while searching for clues as I had gotten the same error message. I thought this answer was helpful. It is easy to typo as things get more complicated.
But I'm pretty sure my situation was free of typos. I think another possible cause is that Eclipse just gets messed up sometimes, if one is doing things that are a little unusual that affect the file structure or build configuration.
Sometimes the best thing to do (after trying a Refresh, a Project clean and closing and restarting Eclipse) is to start fresh and build a new project.
I started a new project and everything worked fine. I compared the web.pom and persistence.xml and they were both identical to the failing project, except for the different project names. Maven libraries were the same. Classes were the same. Maybe I overlooked something, but if the error is something internal in Eclipse, starting fresh is probably the best.
I'm coding an app that uses Servlet 3.0, Jsp, and JPA 2.0 and i'm deploying it into Websphere application server 8.5.
Since i already configured into the ibm websphere console, the data source and the jdbc driver, and the j2c authentification (i'm using oracle 11g as a database ). I dont know how my persistence.xml should look like, if i need to specify and add openJPA jars to my project.
For now anything i put into persistence.xml i'm having this issue :
Error 500: <openjpa-2.2.3-SNAPSHOT-r422266:1764177 fatal user error> org.apache.openjpa.persistence.ArgumentException
What should i do ? maybe i'm missing how JPA works
Thanks in advance
The OpenJPA jars should be provided by WebSphere and available to use for your application. There is a JPA sample available here: https://developer.ibm.com/wasdev/downloads/#asset/samples-Java_Persistence_API_JPA_Sample
In the sample, you can see an example of the 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="jpasamplepersistenceunit">
<jta-data-source>java:comp/env/jdbc/samplejpadatasource</jta-data-source>
<non-jta-data-source>java:comp/env/jdbc/samplejpadatasourcenonjta</non-jta-data-source>
<class>wasdev.sample.jpa.Thing</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<!-- These properties are creating the database on the fly. We are using them to avoid users having
to create a database to run the sample.
See also the create=true line in the datasource meta data. -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
<property name="openjpa.jdbc.DBDictionary" value="derby" />
<!-- EclipseLink specific properties to create the database. They are only used if using the jpa-2.1 feature. -->
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>
</persistence-unit>
</persistence>
I think your error is not caused by the OpenJPA jars not being available. It might be because your database is not configured correctly. Make sure your persistence.xml file refers to your datasources properly.
I'm trying to create a layered web proyect with an EAR. I divided the Entities from the DataAccess in order to only allow DataAccess to be called by BusinessLogic.
I'm actually getting this exception:
Object: co.edu.icesi.i2trading.entities.Statetype#21397ba0 is not a known entity type.
And I found here that I need to create a persistence.xml in the EAR, but I can't really understand how.
Sharing a persistence unit across components in a .ear file
I tried placing the XML file in the Configuration Files:
And referencing the jar with <jar-files> in the persistence.xml;
<?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="I2TradingDataAccessPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/I2DataSource</jta-data-source>
<jar-file>../I2TradingEntities.jar</jar-file>
<jar-file>../../I2TradingEntities.jar</jar-file>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="eclipselink.target-server" value="None"/>
<!-- <property name="eclipselink.logging.level" value="ALL"/> -->
<property name="eclipselink.logging.level" value="WARNING"/>
</properties>
</persistence-unit>
</persistence>
With no success. Any idea why? I'm very new to Web Developing and this is getting to my nerves.
I'm also getting this WARNING in the persistence.xml's DESIGN tab:
I believe that the instruction jar-file interprets any path from the file that holds the persistence.xml... So, your configuration specifies that the Entities JAR are siblings of your EAR file.
The best (and easy) solution for your problem is to put the given persistence.xmlat the META-INF folder of your I2TradingEntities.jar and remove the <jar-file> instructions from it ... This will instruct the Application Server to create a PersistenceContext called "I2TradingDataAccessPU" and to detect any #Entity Class contained in that JAR.
I have an application running on Glassfish 4.1 that uses a JDBC Resource. In the application itself I have a persistence.xml file that lists all the entities and tells the container which JDBC Resource to use. I have defined some properties to log the SQL it executes. It looks something like this:
<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="MyResource_PU" transaction-type="JTA">
<jta-data-source>jdbc/my_resource</jta-data-source>
<class>com.example.entities.EntityOne</class>
<class>com.example.entities.EntityTwo</class>
<class>com.example.entities.EntityThree</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
Now when this application goes to production, I don't want the SQL to be logged. So every time I do a release, I need to remind myself to change the eclipselink.logging properties.
I thought, there should be a better way to handle this. So I went to the Glassfish admin console, to JDBC Resources and added the 2 properties there, but that doesn't work.
Is there any way to remove the "environment specific" values out of the persistence.xml file and into the Glassfish configuration? I have googled for a while now, but don't seem to find the correct sollution. What I did find is that Hibernate has the option to specify a "configuration file", but I haven't found this for EclipseLink.
We used maintain property files for each environment such as DEV,QA,PROD,UAT etc in different files and copy one of them during build.
Ant build
<property environment="env" />
<!-- ***** COMMAND LINE ARGUMENTS DEMOED HERE -->
<property name="build_type" value= "${env.build_type}"/>
<copy todir="deploy">
<fileset dir="src_dir"/>
<globmapper from=${env.build_type}".persistence.xml" to="persistence.xml"/>
</copy>
Run build like this
ant -Denv.build_type=PROD
This will copy PROD.persistence.xml to persistence.xml
ant -Denv.build_type=DEV
This will copy DEV.persistence.xml to persistence.xml
As per glassfish documentation, persistence.xml settings are meant to take precedence over global settings, so I wouldn't recommend anything in a persistence.xml file that you would want to override later.
That said, EclipseLink server integration can make use of a server log, allowing external control over settings. See this for a description of setting logging properties in glassfish that should control the log file EclipseLink writes to. Otherwise, you can define a different log mechanism in your peristence.xml file, such as log4J or a custom one that you can control how you wish as touched on here
In my Java/Seam/JbossAS app, I decided to externalize my Model classes (hibernate entities) and moved them into another project. The project produces model.jar, which is then used by the main app. The model.jar dependency is resolved by Ivy.
Building the main app with Ant works without problems. Then I copy manually the model.jar into 'mainapp.ear/lib' directory. Afterwards I deploy the app and there are no problems (although I notice that there are is no log info about found mappings). But when I want to login, I get the exception:
javax.el.ELException: javax.ejb.EJBTransactionRolledbackException:
org.hibernate.hql.ast.QuerySyntaxException: AppUser is not
mapped [select u from AppUser u where u.userName = :usernamePar]
There were no code changes in the meantime, just externalizing some of the classes into a jar. Does this mean, that I need the source code of the Model classes when compiling the main app?
The EntityManagerFactory is built for scanning entities only from the jar that has a /META-INF/persistence.xml file into.
In order to scan other jars you have to use <jar-file>:
<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="manager1" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/DefaultDS</jta-data-source>
<mapping-file>ormap.xml</mapping-file>
<jar-file>MyApp.jar</jar-file>
<class>org.acme.Employee</class>
<class>org.acme.Person</class>
<class>org.acme.Address</class>
<shared-cache-mode>ENABLE_SELECTOVE</shared-cache-mode>
<validation-mode>CALLBACK</validation-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
See 2.2.1 Packaging in Hibernate doc.
Also check if your hibernate mappings are correctly placed wrt hibernate config file. Note that hibernate mapping resources or classes are relative to the location of hibernate.cfg.xml file.