EclipseLink compilation error - java

I have a maven project on NetBeans that have a Resteasy service running, this with no problem, and when I tried to add database access to use with the service using Hibernate(EclipseLink) I am getting a error:
Problem with Filer: Attempt to recreate a file for type my.package.MyClass_
I have no idea why this is happening, any tip?
Thanks in advice.
EDIT
Here is mu persstence.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="br.com.meraki.curtamix_CurtamixREST_war_1PU" transaction-type="JTA">
<jta-data-source>curtamix</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties/>
</persistence-unit>
</persistence>

Related

Transactional wrapped method dont persist or remove

Hi i got a problem with a CDI Named Bean wich is #Transactional.
I use the WildFly 11.1.0.Final.
Here the Code: https://gist.github.com/stefanwendelmann/7a1f8352900067d5a59826d6ee205044
This is the 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="QuoLoco" transaction-type="JTA">
<description>Verbindung zur QuoLoco Datenbank</description>
<jta-data-source>java:/QUOLOCO_NORM</jta-data-source>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.id.new_generator_mappings" value="false"/>
</properties>
</persistence-unit>
</persistence>
When i call the method "doChange" and only edited Empfangseinheittypenparameter, the em.remove and em.persist dont trigger a flush.
When i call the method "doChange" and edited some of the main  Empfangseinheittypen empfangseinheittyp, i make a find on the Empfangseinheittypenparameter dont need a flush
What am a doing wrong?
Both methods are public.
Please see a picture of the Application attatched
Thanks in advance for your help
According to the comments, doChange is called from the same bean.
The problem is similar to #Transactional method called from another method doesn't obtain a transaction which means, that the transaction will not end with doChange, so you can not expect a flush to be done when returning from the method.

Cannot resolve column name

I'm using JPA with hibernate under my small resteasy project deployed on wildfly.
I've got my persistence.xml file under directory:
resources/META-INF/
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<persistence-unit name="PostgresDS" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/PostgresDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
So I'm dropping and creating database each time on startup.
When typing annotation #Column(name="SomeName") I've got error that
"Cannot resolve column "Name" "
and as fix I'm supposed to attach data-source.
Should I prepare some hibernate config file(attaching data-source didn't help), maybe disabling some validation ?

Get all available persistence-unit names defined in persistence.xml

I have persistence.xml as below (just an example) and I want to retrieve set of all persistence-unit names. In this example a,b and c
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="a">
</persistence-unit>
<persistence-unit name="b">
</persistence-unit>
<persistence-unit name="c">
</persistence-unit>
</persistence>
You can get all persistence unit names using this code.
List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(new Properties());
for (ParsedPersistenceXmlDescriptor descriptor : persistenceUnits) {
AVAILABLE_MODULES_LIST.add(descriptor.getName());
}
For me it works fine.

Ljava.lang.String class cannot be resolved in persistence.xml

I am using JBoss Developer Studio. I have a project with a persistence.xml file. The file is perfect to me, but I keep getting this error on the tab that lists all the Problems of my project.
Class "[Ljava.lang.String;#22ec7158" cannot be resolved
I include the picture for a better context.
When I click on the error, so that it takes me to the place where the error is happening, it takes me to the end of the file.
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="Persistence">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/MemberOfferDS</jta-data-source>
<class>com.bbb.memberoffer.model.SycsCoordinator</class>
<class>com.bbb.aicweb.memberoffer.model.SycsCoordinatorPhoneNumber</class>
<class>com.bbb.memberoffer.model.SycsCoordinatorClub</class>
<class>com.bbb.memberoffer.model.SycsCoordinatorSecurityGroup</class>
<class>com.bbb.memberoffer.model.SycsCoordinatorClubPk</class>
<class>com.bbb.memberoffer.model.PhoneNumberType</class>
<class>com.bbb.memberoffer.model.Club</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<!-- Not sure if this is the right one to use or not? -->
<property name='hibernate.show_sql' value='true' />
<property name='hibernate.format_sql' value='true' />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
</properties>
</persistence-unit>
</persistence>
You may have solved this already, however, in my case the problem was caused by referencing a class in a element that no longer existed.
EDIT: The exact reason for this type of error message is that the error generator is trying to run a toString() on a String array when it generates the error message.

TomEE pointing to wrong DataSource

I'm using a single TomEE instance to deploy 2 Webapplications. Both applications use a different database and different entities.
Application 2 is integrated into Application 1, so I need both the schema anytime while running.
I have both DataSources configured in the tomee.xml like this:
<tomee>
<Resource id="testDBPool" type="DataSource">
jdbcDriver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/testDB"
username = "admin"
password = "admin"
</Resource>
</tomee>
<tomee>
<Resource id="testDBPool2" type="DataSource">
jdbcDriver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/testDB2"
username = "admin"
password = "admin"
</Resource>
</tomee>
In Application 1 I use this 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="testDBPool" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/testDBPool</jta-data-source>
</persistence-unit>
</persistence>
In Application 2 I use this 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="testDBPool2" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/testDBPool2</jta-data-source>
</persistence-unit>
</persistence>
When I tried to run application then it is throwing testDB.table1 is not exist, whereas actually the table1 exist in testDB2 schema not in testDB, I do not understand why it is pointing to wrong schema?
It seems to me that your persistence.xml of Application2 is never loaded. That is not so surprising as there already is a presistence.xml running for the context.
Try adding the entries from Application2 into Application 1 and see if that works out.
Alternatively have a look at this question: How can I make a JPA application access different databases? and see if it helps.
If both didn't work untie Application2 from Application1 and run them in different contexts so each of them has its own persistence.xml running then debug it again.

Categories

Resources