How to setup gradle JavaFX application in IntelliJ with Hibernate & JPA - java

What is the best way to setup a new Gradle project in IntelliJ IDEA version 2021.3.2?
Specifically, I am trying to setup JPA/Hibernate and am fairly new to this, but cannot seem to get it to work.
I have added the following in build.gradle, as per the IntelliJ guide:
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
compileOnly('javax.persistence:javax.persistence-api:2.2')
implementation('org.hibernate:hibernate-core:5.6.5.Final')
}
When I try adding #Entity on a class, it is unable to compile as the Class is not recognised.
I also have the following persistence.xml file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="default">
</persistence-unit>
</persistence>

Related

MULE 4 IntelliJ resolving xsd schemas

I am trying to use IntelliJ as IDE instead of Anypoint Studio because it runs very bad on windows. I've downloaded the plugin, but I'm having troubles setting up the xsd references of the connectors, it keeps complaining that it cannot find the xsd.
The mule xsd are pointing to a location over the internet which doesn't exist, I think that it must be resolved against the pom dependencies, but I don't know how to tell this to the IDE.
Here's an example of my mule app (which runs fine on Anypoint Studio):
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:ftps="http://www.mulesoft.org/schema/mule/ftps"
xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"
xmlns:java="http://www.mulesoft.org/schema/mule/java"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/java http://www.mulesoft.org/schema/mule/java/current/mule-java.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd
http://www.mulesoft.org/schema/mule/ftps http://www.mulesoft.org/schema/mule/ftps/current/mule-ftps.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd">
<flow name="post:ProcessPayment" doc:id="ccaba1bf-94b0-412c-895d-6bc118b0b878"> ...
And this is the error shown from IntelliJ:
You are using a plugin for DataWeave 2.0, it is not meant to support Mule 4 XML configuration files

No resource files named META-INF/services/javax.persistence.spi.PersistenceProvider were found [duplicate]

I am using EclipseLink and even I have all necessary jar files imported with maven, I get still the Exception:
Exception in thread "main" javax.persistence.PersistenceException: No
resource files named
META-INF/services/javax.persistence.spi.PersistenceProvider were
found. Please make sure that the persistence provider jar file is in
your classpath.
In Maven pom I have the dependency:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
Here is my 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="PersistenzJPAProjekt">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.testJPABasis.Person</class>
</persistence-unit>
</persistence>
Here the clathpath in eclipse:
The class which actually generates the exception:
public class TestJPA
{
public static void main(String[] args)
{
Person person = new Person();
person.setPersonID(1);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenzJPAProjekt");
EntityManager em = emf.createEntityManager();
}
}
The persistence.xml is directly under META-INF. As far as I know I don't need to have Glassfish or Tomcat as EclipseLink is made for standalone applications. If I am wrong maybe this is then the cause. The Meta-Inf is placed in:
persistence-api is just that: the API (mostly interfaces). You still need to include the actual persistence provider; it looks like you're wanting EclipseLink.

How to store timestamp in Maven Surefire generated report.xml?

Is there a way, to instruct Maven Surefire, to save the test starting time of each JUnit Test Case in the report xml file?
I expect that the report should look a bit like this:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.chris.testcases.Timestamp" time="1,962.965" tests="1" errors="0" skipped="0" failures="0">
<properties>
<property ...>
</properties>
<testcase
name="Timestampfilter"
classname="com.chris.testcases.Timestamp"
time="1,339.383" <-- this is the already existing execution time
--> timestamp="2015-03-11 16:44:05" /> <-- this is the NEW attribute I need
...
</testsuite>
Background: I need this paramter for future processing in this xml, and just writing the timestamp in the "normal" logfile/output is no solution.
I am using: Maven 3.2.5 with Surefire-Plugin 2.18.1.
Update: I found an similar question here: https://jira.codehaus.org/browse/SUREFIRE-681

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.

EclipseLinke:No resource files named META-INF/services/javax.persistence.spi:No PersistenceProvider were found

I am using EclipseLink and even I have all necessary jar files imported with maven, I get still the Exception:
Exception in thread "main" javax.persistence.PersistenceException: No
resource files named
META-INF/services/javax.persistence.spi.PersistenceProvider were
found. Please make sure that the persistence provider jar file is in
your classpath.
In Maven pom I have the dependency:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
Here is my 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="PersistenzJPAProjekt">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.testJPABasis.Person</class>
</persistence-unit>
</persistence>
Here the clathpath in eclipse:
The class which actually generates the exception:
public class TestJPA
{
public static void main(String[] args)
{
Person person = new Person();
person.setPersonID(1);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenzJPAProjekt");
EntityManager em = emf.createEntityManager();
}
}
The persistence.xml is directly under META-INF. As far as I know I don't need to have Glassfish or Tomcat as EclipseLink is made for standalone applications. If I am wrong maybe this is then the cause. The Meta-Inf is placed in:
persistence-api is just that: the API (mostly interfaces). You still need to include the actual persistence provider; it looks like you're wanting EclipseLink.

Categories

Resources