Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducer for HHH-18618 #428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions orm/hibernate-orm-6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<name>Hibernate ORM 6 Test Case Template</name>

<properties>
<version.com.h2database>2.3.232</version.com.h2database>
<version.org.testcontainers>1.16.3</version.org.testcontainers>
<version.pgjdbc>42.7.4</version.pgjdbc>
<version.junit-jupiter>5.11.0</version.junit-jupiter>
<version.org.hibernate.orm>6.6.0.Final</version.org.hibernate.orm>
<version.org.assertj.assertj-core>3.26.3</version.org.assertj.assertj-core>
Expand All @@ -30,6 +31,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>1.20.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -43,10 +51,17 @@
<artifactId>hibernate-testing</artifactId>
</dependency>


<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${version.pgjdbc}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${version.com.h2database}</version>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package org.hibernate.bugs;

import org.hibernate.cfg.AvailableSettings;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import org.hibernate.bugs.model.Currency;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
Expand All @@ -35,36 +39,28 @@
*/
@DomainModel(
annotatedClasses = {
// Add your entities here.
// Foo.class,
// Bar.class
},
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
xmlMappings = {
// "org/hibernate/test/Foo.hbm.xml",
// "org/hibernate/test/Bar.hbm.xml"
Currency.class
}
)
@ServiceRegistry(
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
settings = {
// For your own convenience to see generated queries:
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),

// Add your own settings that are a part of your quarkus configuration:
// @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
}
)
@SessionFactory
@SessionFactory(exportSchema = false)
class ORMUnitTestCase {

// Add your tests, using standard JUnit 5.
@Test
void hhh123Test(SessionFactoryScope scope) throws Exception {
void hhh18618Test(SessionFactoryScope scope) throws Exception {
scope.inTransaction( session -> {
// Do stuff...
List<Integer> numbers = List.of(840, 978);
List<Currency> currencies = session.createQuery(
"FROM Currency "
+ "WHERE array_contains(:numbers, number)",
Currency.class)
.setParameter("numbers", numbers.toArray(Integer[]::new))
.getResultList();
assertEquals(2, currencies.size());
} );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.hibernate.bugs.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

@Entity
public class Currency {

@Id
@Column(name = "num", nullable = false, updatable = false)
private Integer number;

public Integer getNumber() {
return number;
}

public void setNumber(Integer number) {
this.number = number;
}

}
10 changes: 5 additions & 5 deletions orm/hibernate-orm-6/src/test/resources/hibernate.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
#

hibernate.dialect org.hibernate.dialect.H2Dialect
hibernate.connection.driver_class org.h2.Driver
hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class org.testcontainers.jdbc.ContainerDatabaseDriver
#hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
hibernate.connection.username sa
hibernate.connection.password
hibernate.connection.url jdbc:tc:postgresql:9.6.8:///databasename?TC_INITSCRIPT=file:src/test/resources/postgres_array.sql
hibernate.connection.username test
hibernate.connection.password test

hibernate.connection.pool_size 5

Expand Down
11 changes: 11 additions & 0 deletions orm/hibernate-orm-6/src/test/resources/postgres_array.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE currency (
num NUMERIC(3) NOT NULL,
CONSTRAINT pk_currency PRIMARY KEY(num)
);

INSERT INTO currency(num)
VALUES (392),
(756),
(826),
(840),
(978);