Skip to content

Commit

Permalink
Merge pull request jakartaee#1291 from beikov/tckrefactor-jpa-fixes
Browse files Browse the repository at this point in the history
Improve usability of JPA TCK
  • Loading branch information
alwin-joseph authored Apr 30, 2024
2 parents 4b9de61 + e4d7c2a commit 53add1b
Show file tree
Hide file tree
Showing 29 changed files with 509 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ DROP TABLE RETAILORDER_CONSUMER;
CREATE TABLE RETAILORDER_CONSUMER(CONSUMERS_ID BIGINT NOT NULL,ORDERS_ID BIGINT NOT NULL);

DROP TABLE THEATRELOCATION1;
CREATE TABLE THEATRELOCATION1(ID BIGINT NOT NULL, CODE VARCHAR(255),TCOMP_ID BIGINT NOT NULL);
CREATE TABLE THEATRELOCATION1(ID BIGINT NOT NULL, CODE VARCHAR(255),TCOMP_ID BIGINT);

DROP TABLE THEATRECOMPANY1;
CREATE TABLE THEATRECOMPANY1(ID BIGINT NOT NULL,NAME VARCHAR(255));
Expand Down
315 changes: 230 additions & 85 deletions jpa/bin/pom.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
<artifactId>shrinkwrap-api</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>3.1.4</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
18 changes: 18 additions & 0 deletions jpa/spec-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# JPA spec tests

## Running in IntelliJ

Create a run configuration for a test and add the following system properties for e.g. PostgreSQL with Hibernate ORM

* `-Dplatform.mode=standalone`
* `-Dpersistence.unit.name=JPATCK`
* `-Dpersistence.unit.name.2=JPATCK2`
* `-Djakarta.persistence.jdbc.user=hibernate_orm_test`
* `-Djakarta.persistence.jdbc.password=hibernate_orm_test`
* `-Djdbc.db=postgresql`
* `-Ddb.supports.sequence=true`
* `-Djakarta.persistence.provider=org.hibernate.jpa.HibernatePersistenceProvider`
* `-Djakarta.persistence.jdbc.driver=org.postgresql.Driver`
* `-Djakarta.persistence.jdbc.url=jdbc:postgresql://localhost/hibernate_orm_test?preparedStatementCacheQueries=0&escapeSyntaxCallMode=callIfNoReturn`
* `-Djpa.provider.implementation.specific.properties=hibernate.query.jpaql_strict_compliance=true:hibernate.id.new_generator_mappings=true:hibernate.cache.region.factory_class=org.hibernate.testing.cache.CachingRegionFactory:hibernate.model.generator_name_as_sequence_name=true:hibernate.jpa.compliance.transaction=true:hibernate.jpa.compliance.closed=true:hibernate.jpa.compliance.query=true:hibernate.jpa.compliance.list=true:hibernate.jpa.compliance.caching=true:hibernate.jpa.compliance.global_id_generators=true:hibernate.jpa.compliance=true:hibernate.type.wrapper_array_handling=legacy:hibernate.type.preferred_uuid_jdbc_type=char:hibernate.show_sql=true`
* `-Dpersistence.second.level.caching.supported=true`
128 changes: 128 additions & 0 deletions jpa/spec-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,132 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>hibernate</id>
<properties>
<hibernate.version>7.0.0</hibernate.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-platform</artifactId>
<version>${hibernate.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-testing</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.models</groupId>
<artifactId>hibernate-models</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>db2</id>
<properties>
<db2.jdbc.version>11.5.9.0</db2.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>derby</id>
<properties>
<derby.jdbc.version>10.15.2.0</derby.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>${derby.jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>${derby.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>mssqlserver</id>
<properties>
<mssqlserver.jdbc.version>12.4.2.jre11</mssqlserver.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssqlserver.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>mysql</id>
<properties>
<mysql.jdbc.version>8.2.0</mysql.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>${mysql.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>oracle</id>
<properties>
<oracle.jdbc.version>23.3.0.23.09</oracle.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>${oracle.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>postgresql</id>
<properties>
<postgresql.jdbc.version>42.6.2</postgresql.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public void nativeQueryTest2() throws Exception {
getEntityManager().persist(o9);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select o.\"ID\" AS \"OID\", o.\"TOTALPRICE\" AS \"OPRICE\", "
+ "o.\"FK1_FOR_ITEM\" AS \"OITEM\", i.\"ITEMNAME\" AS \"INAME\" from \"ORDER1\" o, \"ITEM\" i "
+ "WHERE (o.\"TOTALPRICE\" < 100) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", "Order2ItemResults")
q = getEntityManager().createNativeQuery("Select o.ID AS \"OID\", o.TOTALPRICE AS \"OPRICE\", "
+ "o.FK1_FOR_ITEM AS \"OITEM\", i.ITEMNAME AS \"INAME\" from ORDER1 o, ITEM i "
+ "WHERE (o.TOTALPRICE < 100) AND (o.FK1_FOR_ITEM = i.ID)", "Order2ItemResults")
.getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -217,9 +217,9 @@ public void nativeQueryTest3() throws Exception {

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager()
.createNativeQuery("Select o.\"ID\" AS \"THISID\", o.\"TOTALPRICE\" AS \"THISPRICE\", "
+ "o.\"FK1_FOR_ITEM\" AS \"THISITEM\", i.\"ID\", i.\"ITEMNAME\" from \"ORDER1\" o, \"ITEM\" i "
+ "WHERE (o.\"TOTALPRICE\" > 140) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", "Order3ItemResults")
.createNativeQuery("Select o.ID AS \"THISID\", o.TOTALPRICE AS \"THISPRICE\", "
+ "o.FK1_FOR_ITEM AS \"THISITEM\", i.ID, i.ITEMNAME from ORDER1 o, ITEM i "
+ "WHERE (o.TOTALPRICE > 140) AND (o.FK1_FOR_ITEM = i.ID)", "Order3ItemResults")
.getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -322,9 +322,9 @@ public void nativeQueryColumnResultTypeTest() throws Exception {
getEntityManager().persist(o9);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select o.\"ID\" AS \"OID\", o.\"TOTALPRICE\" AS \"OPRICE\", "
+ "o.\"FK1_FOR_ITEM\" AS \"OITEM\", i.\"ITEMNAME\" AS \"INAME\" from \"ORDER1\" o, \"ITEM\" i "
+ "WHERE (o.\"TOTALPRICE\" < 100) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", "Order4ItemResults")
q = getEntityManager().createNativeQuery("Select o.ID AS \"OID\", o.TOTALPRICE AS \"OPRICE\", "
+ "o.FK1_FOR_ITEM AS \"OITEM\", i.ITEMNAME AS \"INAME\" from ORDER1 o, ITEM i "
+ "WHERE (o.TOTALPRICE < 100) AND (o.FK1_FOR_ITEM = i.ID)", "Order4ItemResults")
.getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -430,9 +430,9 @@ public void nativeQueryTestConstructorResult() throws Exception {
logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager()
.createNativeQuery(
"Select o.\"ID\" AS \"OID\", o.\"TOTALPRICE\" AS \"OPRICE\", "
+ "i.\"ITEMNAME\" AS \"OITEMNAME\" from \"ORDER1\" o, \"ITEM\" i "
+ "WHERE (o.\"TOTALPRICE\" < 100) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")",
"Select o.ID AS \"OID\", o.TOTALPRICE AS \"OPRICE\", "
+ "i.ITEMNAME AS \"OITEMNAME\" from ORDER1 o, ITEM i "
+ "WHERE (o.TOTALPRICE < 100) AND (o.FK1_FOR_ITEM = i.ID)",
"Order5ItemResults")
.getResultList();

Expand Down Expand Up @@ -500,8 +500,8 @@ public void nativeQueryTestConstructorResultWithId() throws Exception {

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery(
"Select o.\"ID\" AS \"OID\", o.\"TOTAL\" AS \"PTOTAL\" from \"PURCHASE_ORDER\" o "
+ "WHERE (o.\"TOTAL\" < 50)",
"Select o.ID AS \"OID\", o.TOTAL AS \"PTOTAL\" from PURCHASE_ORDER o "
+ "WHERE (o.TOTAL < 50)",
"PurchaseOrder1Results").getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -568,7 +568,7 @@ public void nativeQueryTestConstructorResultNoId() throws Exception {

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery(
"Select o.\"TOTAL\" AS \"PTOTAL\" from \"PURCHASE_ORDER\" o " + "WHERE (o.\"TOTAL\" < 50)",
"Select o.TOTAL AS \"PTOTAL\" from PURCHASE_ORDER o " + "WHERE (o.TOTAL < 50)",
"PurchaseOrder2Results").getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -640,7 +640,7 @@ public void createNativeQueryStringTest() throws Exception {
getEntityManager().persist(o3);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select o.\"ID\" from \"ORDER1\" o WHERE o.\"ID\" = 2 ")
q = getEntityManager().createNativeQuery("Select o.ID from ORDER1 o WHERE o.ID = 2 ")
.getResultList();

List<Integer> actual = new ArrayList<Integer>();
Expand Down Expand Up @@ -703,7 +703,7 @@ public void createNativeQueryResultClassTest() throws Exception {
getEntityManager().persist(o3);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select * from \"ORDER1\" o WHERE o.\"ID\" = 2 ", Order1.class)
q = getEntityManager().createNativeQuery("Select * from ORDER1 o WHERE o.ID = 2 ", Order1.class)
.getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -765,7 +765,7 @@ public void createNativeQueryResultClassTQTest() throws Exception {
getEntityManager().persist(o3);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select * from \"ORDER1\" o WHERE o.\"ID\" = 2 ", Order1.class)
q = getEntityManager().createNativeQuery("Select * from ORDER1 o WHERE o.ID = 2 ", Order1.class)
.getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -804,7 +804,7 @@ public void createNativeQueryResultClassTQTest() throws Exception {
public void executeUpdateTransactionRequiredExceptionTest() throws Exception {
boolean pass = false;
try {
getEntityManager().createNativeQuery("Delete from \"ORDER1\"").executeUpdate();
getEntityManager().createNativeQuery("Delete from ORDER1").executeUpdate();
logger.log(Logger.Level.ERROR, "TransactionRequiredException was not thrown");
} catch (TransactionRequiredException ise) {
logger.log(Logger.Level.TRACE, "Received expected TransactionRequiredException");
Expand Down Expand Up @@ -857,7 +857,7 @@ public void setParameterTest() throws Exception {
getEntityManager().persist(o3);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select * from \"ORDER1\" o WHERE o.\"ID\" = ? ", Order1.class)
q = getEntityManager().createNativeQuery("Select * from ORDER1 o WHERE o.ID = ? ", Order1.class)
.setParameter(1, 2).getResultList();

if (q.size() != 1) {
Expand Down Expand Up @@ -917,7 +917,7 @@ public void getSingleResultTest() throws Exception {
getEntityManager().persist(o3);

logger.log(Logger.Level.TRACE, "Execute Query");
q = getEntityManager().createNativeQuery("Select COUNT(*) from \"ORDER1\" o").getSingleResult();
q = getEntityManager().createNativeQuery("Select COUNT(*) from ORDER1 o").getSingleResult();
int i = 0;
i = convertToInt(q);
if (i == 3) {
Expand Down Expand Up @@ -957,9 +957,9 @@ private void removeTestData() {
try {
getEntityTransaction().begin();
getEntityManager().createNativeQuery("Delete FROM ORDER2").executeUpdate();
getEntityManager().createNativeQuery("Delete FROM \"ORDER1\"").executeUpdate();
getEntityManager().createNativeQuery("Delete FROM \"ITEM\"").executeUpdate();
getEntityManager().createNativeQuery("Delete FROM \"PURCHASE_ORDER\"").executeUpdate();
getEntityManager().createNativeQuery("Delete FROM ORDER1").executeUpdate();
getEntityManager().createNativeQuery("Delete FROM ITEM").executeUpdate();
getEntityManager().createNativeQuery("Delete FROM PURCHASE_ORDER").executeUpdate();

getEntityTransaction().commit();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,8 @@ public void currentDate() throws Exception {

Date result = tq.getSingleResult();
Date d = Date.valueOf(result.toString());
if (d.equals(result)) {
// Use String.equals because java.sql.Date will compare milliseconds and current_date will contain these
if (d.toString().equals(result.toString())) {
logger.log(Logger.Level.TRACE, "Successfully returned expected results");
pass = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ public void testOrPredicateAsListOfN() throws Exception {
cQuery.where(cb.or(List.of(
cb.equal(root.get("strVal1"), cb.parameter(String.class, "strParam1")),
cb.equal(root.get("strVal1"), cb.parameter(String.class, "strParam2")),
cb.equal(root.get("timeVal"), cb.parameter(String.class, "timeParam")),
cb.equal(root.get("dateVal"), cb.parameter(String.class, "dateParam"))
cb.equal(root.get("timeVal"), cb.parameter(LocalTime.class, "timeParam")),
cb.equal(root.get("dateVal"), cb.parameter(LocalDate.class, "dateParam"))
)));
TypedQuery<CriteriaEntity> query = getEntityManager().createQuery(cQuery);
query.setParameter("strParam1", "Left");
Expand Down Expand Up @@ -902,7 +902,7 @@ public void testExtractSecondFromTime() throws Exception {
cb.parameter(Integer.class, "timeParam"),
cb.extract(LocalTimeField.SECOND, root.get("timeVal"))));
TypedQuery<CriteriaEntity> query = getEntityManager().createQuery(cQuery);
query.setParameter("timeParam", 12);
query.setParameter("timeParam", 12d);
List<CriteriaEntity> result = query.getResultList();
if (EXPECTED_SIZE == result.size()) {
logger.log(System.Logger.Level.TRACE, "Received expected result size:|" + result.size() + "|");
Expand Down Expand Up @@ -1177,7 +1177,7 @@ public void testExpressionEqualToExpression() throws Exception {
if (cQuery != null) {
Root<CriteriaEntity> root = cQuery.from(CriteriaEntity.class);
cQuery.where(
root.get("strVal1").equalTo(cb.parameter(Integer.class, "strParam")));
root.get("strVal1").equalTo(cb.parameter(String.class, "strParam")));
TypedQuery<CriteriaEntity> query = getEntityManager().createQuery(cQuery);
query.setParameter("strParam", "LeftToken");
List<CriteriaEntity> result = query.getResultList();
Expand Down Expand Up @@ -1266,7 +1266,7 @@ public void testExpressionNotEqualToExpression() throws Exception {
if (cQuery != null) {
Root<CriteriaEntity> root = cQuery.from(CriteriaEntity.class);
cQuery.where(
root.get("strVal1").notEqualTo(cb.parameter(Integer.class, "strParam")));
root.get("strVal1").notEqualTo(cb.parameter(String.class, "strParam")));
TypedQuery<CriteriaEntity> query = getEntityManager().createQuery(cQuery);
query.setParameter("strParam", "LeftToken");
List<CriteriaEntity> result = query.getResultList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ private void removeTestData() {
}
try {
getEntityTransaction().begin();
getEntityManager().createNativeQuery("DELETE FROM \"COFFEE\"").executeUpdate();
getEntityManager().createNativeQuery("DELETE FROM COFFEE").executeUpdate();
getEntityTransaction().commit();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception encountered while removing entities:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import jakarta.persistence.Table;

@NamedNativeQueries({
@NamedNativeQuery(name = "findAllSQLCoffees2", query = "select \"ID\", \"BRANDNAME\", \"PRICE\" from \"COFFEE\"", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class),
@NamedNativeQuery(name = "findAllSQLCoffees", query = "select \"ID\", \"BRANDNAME\", \"PRICE\" from \"COFFEE\"", resultSetMapping = "CoffeeResult"),
@NamedNativeQuery(name = "xmlOverridesNamedNativeQuery", query = "select \"ID\", \"BRANDNAME\", \"PRICE\" from \"COFFEE\"", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class) })
@NamedNativeQuery(name = "findAllSQLCoffees2", query = "select ID, BRANDNAME, PRICE from COFFEE c", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class),
@NamedNativeQuery(name = "findAllSQLCoffees", query = "select ID, BRANDNAME, PRICE from COFFEE c", resultSetMapping = "CoffeeResult"),
@NamedNativeQuery(name = "xmlOverridesNamedNativeQuery", query = "select ID, BRANDNAME, PRICE from COFFEE c", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class) })
@SqlResultSetMapping(name = "CoffeeResult", entities = @EntityResult(entityClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class))
@NamedQueries({
@NamedQuery(name = "findAllCoffees", query = "Select c from Coffee c", lockMode = LockModeType.PESSIMISTIC_READ),
Expand Down
Loading

0 comments on commit 53add1b

Please sign in to comment.