From 32d1455326976ab47cbb2903ee70d94149b50f29 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 27 Nov 2024 16:36:07 +0100 Subject: [PATCH] Fix ReSaveReferencedDeletedEntity for CockroachDB and HANA --- .../hibernate/community/dialect/PostgreSQLLegacyDialect.java | 5 +++-- .../main/java/org/hibernate/dialect/PostgreSQLDialect.java | 5 +++-- .../hibernate/orm/test/id/ReSaveReferencedDeletedEntity.java | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java index 8416fa63cb..13de5ddd8a 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java @@ -199,7 +199,7 @@ public class PostgreSQLLegacyDialect extends Dialect { // "long" string types case LONG32VARCHAR: case LONG32NVARCHAR: - return "varchar"; + return "text"; case BLOB: case CLOB: case NCLOB: @@ -232,9 +232,10 @@ public class PostgreSQLLegacyDialect extends Dialect { case NCHAR: case VARCHAR: case NVARCHAR: + return "varchar"; case LONG32VARCHAR: case LONG32NVARCHAR: - return "varchar"; + return "text"; case BINARY: case VARBINARY: case LONG32VARBINARY: diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index 7c3ac3f15d..508f2a3eee 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -220,7 +220,7 @@ public class PostgreSQLDialect extends Dialect { // since there's no real difference between TEXT and VARCHAR, // except for the length limit, we can just use 'text' for the // "long" string types - case LONG32VARCHAR, LONG32NVARCHAR -> "varchar"; + case LONG32VARCHAR, LONG32NVARCHAR -> "text"; // use oid as the blob/clob type on Postgres because // the JDBC driver doesn't allow using bytea/text via @@ -246,7 +246,8 @@ public class PostgreSQLDialect extends Dialect { @Override protected String castType(int sqlTypeCode) { return switch (sqlTypeCode) { - case CHAR, NCHAR, VARCHAR, NVARCHAR, LONG32VARCHAR, LONG32NVARCHAR -> "varchar"; + case CHAR, NCHAR, VARCHAR, NVARCHAR -> "varchar"; + case LONG32VARCHAR, LONG32NVARCHAR -> "text"; case BINARY, VARBINARY, LONG32VARBINARY -> "bytea"; default -> super.castType( sqlTypeCode ); }; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/ReSaveReferencedDeletedEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/ReSaveReferencedDeletedEntity.java index fb6a21e8c3..02e53f14a9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/ReSaveReferencedDeletedEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/ReSaveReferencedDeletedEntity.java @@ -76,8 +76,9 @@ public class ReSaveReferencedDeletedEntity extends BaseCoreFunctionalTestCase { @Entity(name = "Child") public static class Child { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private Integer id; + private String name; public Integer getId() { return id; @@ -91,7 +92,7 @@ public class ReSaveReferencedDeletedEntity extends BaseCoreFunctionalTestCase { @Entity(name = "Parent") public static class Parent { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private Integer id; @OneToOne(cascade = CascadeType.ALL)