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

HHH-18956 reproducer #465

Open
wants to merge 2 commits 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
22 changes: 22 additions & 0 deletions orm/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
postgres:
container_name: postgres
hostname: postgres
image: postgis/postgis:16-3.5
environment:
POSTGRES_PASSWORD: 'password'
POSTGRES_USER: 'postgres'
POSTGRES_DB: 'database'
ports:
- "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
restart: always
networks:
- nw
networks:
nw:
driver: bridge

volumes:
postgres:
27 changes: 23 additions & 4 deletions orm/hibernate-orm-6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <version>${version.com.h2database}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${version.com.h2database}</version>
<groupId>net.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>2024.1.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
</dependency>

<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-testing</artifactId>
Expand All @@ -70,6 +79,16 @@
<version>${version.org.assertj.assertj-core}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>6.6.3.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package org.hibernate.bugs;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hibernate.bugs.model.Location;
import org.hibernate.bugs.model.Point;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

/**
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
*/
class JPAUnitTestCase {

private static final Long LOCATION_ID = 123412L;
private static final String DOLLAR_QUOTE = "$asdas$";


private EntityManagerFactory entityManagerFactory;

@BeforeEach
Expand All @@ -28,11 +41,44 @@ void destroy() {
// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
void hhh123Test() throws Exception {
void hhh18956Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// Do stuff...

final String query = createNativeQuery();
entityManager.createNativeQuery(query).executeUpdate();

final Location location = entityManager.find(Location.class, LOCATION_ID);
Assertions.assertEquals(LOCATION_ID, location.getId());
Assertions.assertNotNull(location.getPoint());

entityManager.getTransaction().commit();
entityManager.close();
entityManager.close();;
}

private String createNativeQuery() throws JsonProcessingException {
final String nativeQuery = "INSERT INTO location (id, point) " +
"VALUES (%s, %s) " +
"ON CONFLICT DO NOTHING;";

final String dollarQuotedGeoJsonValue = makeDollarQuotedPoint();
final String dollarQuotedId = makeDollarQuotedId();
return String.format(nativeQuery, dollarQuotedId, dollarQuotedGeoJsonValue);
}

private String makeDollarQuotedPoint() throws JsonProcessingException {
final String postgisWrapper = "ST_SetSRID(ST_GeomFromGeoJSON(%s%s%s), 4326)";
return String.format(postgisWrapper, DOLLAR_QUOTE, makePoint(), DOLLAR_QUOTE);
}

private String makeDollarQuotedId() {
return DOLLAR_QUOTE.concat(String.valueOf(LOCATION_ID)).concat(DOLLAR_QUOTE);
}

private String makePoint() throws JsonProcessingException {
Point point = new Point(List.of(30.5, 50.4));
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(point);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.hibernate.cfg.AvailableSettings;

import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
//import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
Expand Down Expand Up @@ -60,7 +60,7 @@
}
)
@SessionFactory
@BytecodeEnhanced
//@BytecodeEnhanced
class QuarkusLikeORMUnitTestCase {

// Add your tests, using standard JUnit.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.hibernate.bugs.model;

import jakarta.persistence.*;
import org.locationtech.jts.geom.Point;

@Entity
public class Location {

@Id
private Long id;

private Point point;

public Location() {
}

public Location(Long id, Point point) {
this.id = id;
this.point = point;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Point getPoint() {
return point;
}

public void setPoint(Point point) {
this.point = point;
}

@Override
public String toString() {
return "Location{" +
"id=" + id +
", point=" + point +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.hibernate.bugs.model;

import java.util.List;

public class Point {

private String type;
private List<Double> coordinates;

public Point() {
type = "Point";
}

public Point(List<Double> coordinates) {
type = "Point";
this.coordinates = coordinates;
}

public String getType() {
return type;
}

public List<Double> getCoordinates() {
return coordinates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>

<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.connection.url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/database"/>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.password" value="password"/>

<property name="hibernate.connection.pool_size" value="5"/>

Expand Down