Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDcxY2I2YTUy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZDcxY2... ) HHH-16554 ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZDcxY2... ) UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZDcxY2... )
Change By: Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Hello Hibernate Team,
I was updating our SpringBoot version from 2.x to 3.x, and I am having trouble with starting our app. I created the tables by using liquibase in the past. When I start my application I see the below exception.
{code:java} Suppressed: java.lang.UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements as well
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:123) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:107) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.dialect.PostgreSQLDialect.getFallbackSqmInsertStrategy(PostgreSQLDialect.java:828) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]{code}
One of my entites looks like the following (I created the sequence in liquibase changelog file) ;
{noformat}import com.fasterxml.jackson.annotation.JsonIgnore;
import java.time.OffsetDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.envers.Audited;
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Audited
public class PaymentAccount {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "payment_account_seq")
@GenericGenerator(
name = "payment_account_seq",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {@Parameter(name = "sequence_name", value = "payment_account_seq")})
@JsonIgnore
private Long id;
private String ciamId;
private String providerName;
private String providerUserId;
@CreationTimestamp
@Column(updatable = false)
private OffsetDateTime createdAt;
@UpdateTimestamp private OffsetDateTime updatedAt;
}
{noformat}
I couldn’t be sure what is causing this issue. I would appreciate if you can help me solve it. You can find the configuration I use below.
* hibernate-envers: 6.1.7.Final
* hibernate-core: 6.1.7.Final
* hibernate-commons-annotations:6.0.6.Final
* spring-boot-starter-data-jpa:3.0.6
* postgresql jdbc driver:42.5.4
* postgres 14
{noformat} datasource:
url: jdbc:postgresql://localhost:8086/mydb
username: admin
password: admin
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 12
idle-timeout: 60000
pool-name: BackendHikariPool
connection-timeout: 45000
minimum-idle: 1
connection-test-query: SELECT 1
type: com.zaxxer.hikari.HikariDataSource
jpa:
show-sql: false
open-in-view: false
hibernate:
ddl-auto: none
properties:
org.hibernate.envers.do_not_audit_optimistic_locking_field: false
hibernate:
namingStrategy: org.hibernate.cfg.ImprovedNamingStrategy
dialect: org.hibernate.dialect.PostgreSQLDialect
hbm2ddl:
auto: none
temp:
use_jdbc_metadata_defaults: false
sql:
init:
continue-on-error: true
platform: org.hibernate.dialect.PostgreSQLDialect{noformat}
( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZmFkOWZjOTdm... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZmFkOW... ) HHH-16554 ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZmFkOW... ) UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZmFkOW... )
Change By: Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Hello Hibernate Team,
I was updating our SpringBoot version from 2.x to 3.x, and I am having trouble with starting our app. I created the tables by using liquibase in the past. When I start my application I see the below exception.
{code:java} Suppressed: java.lang.UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements as well
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:123) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:107) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.dialect.PostgreSQLDialect.getFallbackSqmInsertStrategy(PostgreSQLDialect.java:828) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]{code}
One of my entites looks like the following;
{noformat}import com.fasterxml.jackson.annotation.JsonIgnore;
import java.time.OffsetDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.envers.Audited;
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Audited
public class PaymentAccount {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "payment_account_seq")
@GenericGenerator(
name = "payment_account_seq",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {@Parameter(name = "sequence_name", value = "payment_account_seq")})
@JsonIgnore
private Long id;
private String ciamId;
private String providerName;
private String providerUserId;
@CreationTimestamp
@Column(updatable = false)
private OffsetDateTime createdAt;
@UpdateTimestamp private OffsetDateTime updatedAt;
}
{noformat}
I couldn’t be sure what is causing this issue. I would appreciate if you can help me solve it. You can find the configuration I use below.
* hibernate-envers: 6.1.7.Final
* hibernate-core: 6.1.7.Final
* hibernate-commons-annotations:6.0.6.Final
* spring-boot-starter-data-jpa:3.0.6
* postgresql jdbc driver:42.5.4
* postgres 14
{noformat} datasource:
url: jdbc:postgresql://localhost:8086/mydb
username: admin
password: admin
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 12
idle-timeout: 60000
pool-name: BackendHikariPool
connection-timeout: 45000
minimum-idle: 1
connection-test-query: SELECT 1
type: com.zaxxer.hikari.HikariDataSource
jpa:
show-sql: false
open-in-view: false
hibernate:
ddl-auto: none
properties:
org.hibernate.envers.do_not_audit_optimistic_locking_field: false
hibernate:
namingStrategy: org.hibernate.cfg.ImprovedNamingStrategy
dialect: org.hibernate.dialect.PostgreSQLDialect
hbm2ddl:
auto: none
temp:
use_jdbc_metadata_defaults: false
sql:
init:
continue-on-error: true
platform: org.hibernate.dialect.PostgreSQLDialect{noformat}
( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZmFlZTQ3M2U0... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZmFlZT... ) HHH-16554 ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZmFlZT... ) UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiZmFlZT... )
Change By: Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Hello Hibernate Team,
I was updating our SpringBoot version from 2.x to 3.x, and I am having trouble with starting our app. I create created the tables by using liquibase in the past. When I start my application I see the below exception.
{code:java} Suppressed: java.lang.UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements as well
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:123) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:107) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.dialect.PostgreSQLDialect.getFallbackSqmInsertStrategy(PostgreSQLDialect.java:828) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]{code}
I couldn’t be sure what is causing this issue. I would appreciate if you can help me solve it. You can find the configuration I use below.
* hibernate-envers: 6.1.7.Final
* hibernate-core: 6.1.7.Final
* hibernate-commons-annotations:6.0.6.Final
* spring-boot-starter-data-jpa:3.0.6
* postgresql jdbc driver:42.5.4
* postgres 14
{noformat} datasource:
url: jdbc:postgresql://localhost:8086/mydb
username: admin
password: admin
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 12
idle-timeout: 60000
pool-name: BackendHikariPool
connection-timeout: 45000
minimum-idle: 1
connection-test-query: SELECT 1
type: com.zaxxer.hikari.HikariDataSource
jpa:
show-sql: false
open-in-view: false
hibernate:
ddl-auto: none
properties:
org.hibernate.envers.do_not_audit_optimistic_locking_field: false
hibernate:
namingStrategy: org.hibernate.cfg.ImprovedNamingStrategy
dialect: org.hibernate.dialect.PostgreSQLDialect
hbm2ddl:
auto: none
temp:
use_jdbc_metadata_defaults: false
sql:
init:
continue-on-error: true
platform: org.hibernate.dialect.PostgreSQLDialect{noformat}
( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMGZjYmZlM2Iy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiMGZjYm... ) HHH-16554 ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiMGZjYm... ) UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements ( https://hibernate.atlassian.net/browse/HHH-16554?atlOrigin=eyJpIjoiMGZjYm... )
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core Created: 05/May/2023 00:52 AM Priority: Major Reporter: Ahmet Tanakol ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Hello Hibernate Team,
I was updating our SpringBoot version from 2.x to 3.x, and I am having trouble with starting our app. I create the tables by using liquibase in the past. When I start my application I see the below exception.
Suppressed: java.lang.UnsupportedOperationException: CteInsertStrategy can only be used with Dialects that support CTE that can take UPDATE or DELETE statements as well
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:123) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy.<init>(CteInsertStrategy.java:107) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
at org.hibernate.dialect.PostgreSQLDialect.getFallbackSqmInsertStrategy(PostgreSQLDialect.java:828) ~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
I couldn’t be sure what is causing this issue. I would appreciate if you can help me solve it. You can find the configuration I use below.
* hibernate-envers: 6.1.7.Final
* hibernate-core: 6.1.7.Final
* hibernate-commons-annotations:6.0.6.Final
* spring-boot-starter-data-jpa:3.0.6
* postgresql jdbc driver:42.5.4
* postgres 14
datasource:
url: jdbc:postgresql://localhost:8086/mydb
username: admin
password: admin
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 12
idle-timeout: 60000
pool-name: BackendHikariPool
connection-timeout: 45000
minimum-idle: 1
connection-test-query: SELECT 1
type: com.zaxxer.hikari.HikariDataSource
jpa:
show-sql: false
open-in-view: false
hibernate:
ddl-auto: none
properties:
org.hibernate.envers.do_not_audit_optimistic_locking_field: false
hibernate:
namingStrategy: org.hibernate.cfg.ImprovedNamingStrategy
dialect: org.hibernate.dialect.PostgreSQLDialect
hbm2ddl:
auto: none
temp:
use_jdbc_metadata_defaults: false
sql:
init:
continue-on-error: true
platform: org.hibernate.dialect.PostgreSQLDialect
( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16554#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
Guillaume Toison ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDM4MzAzZDBl... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16553?atlOrigin=eyJpIjoiNDM4Mz... ) HHH-16553 ( https://hibernate.atlassian.net/browse/HHH-16553?atlOrigin=eyJpIjoiNDM4Mz... ) StackOverflowError when loading entities chained together ( https://hibernate.atlassian.net/browse/HHH-16553?atlOrigin=eyJpIjoiNDM4Mz... )
Issue Type: Bug Affects Versions: 6.2.1, 6.2.2 Assignee: Unassigned Components: hibernate-core Created: 04/May/2023 13:00 PM Priority: Blocker Reporter: Guillaume Toison ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... )
Hello,
As originally discussed here https://discourse.hibernate.org/t/stackoverflowerror-in-6-2-with-proxy-la... I’m getting a StackOverflowError on Hibernate 6.2.1 when loading an entities linked to other entities annotated with @Proxy(lazy = false)
The stacktrace looks like this:
at org.hibernate.sql.results.graph.entity.internal.BatchInitializeEntitySelectFetchInitializer.resolveInstance(BatchInitializeEntitySelectFetchInitializer.java:74)
at org.hibernate.sql.results.internal.InitializersList.resolveInstances(InitializersList.java:88)
at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:110)
at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:87)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:179)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:362)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:168)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:93)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(SingleIdEntityLoaderDynamicBatch.java:140)
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(SingleIdEntityLoaderDynamicBatch.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:3367)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3357)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:602)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromCacheOrDatasource(DefaultLoadEventListener.java:588)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:557)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:550)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:202)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:241)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:106)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:78)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:138)
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1231)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1075)
( https://hibernate.atlassian.net/browse/HHH-16553#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16553#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
François Rosière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYzRhYmU2Yzky... ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-16550?atlOrigin=eyJpIjoiYzRhYm... ) HHH-16550 ( https://hibernate.atlassian.net/browse/HHH-16550?atlOrigin=eyJpIjoiYzRhYm... ) Allow accessing the entity identifier from the UserType#nullSafeSet method ( https://hibernate.atlassian.net/browse/HHH-16550?atlOrigin=eyJpIjoiYzRhYm... )
Change By: François Rosière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Hibernate currently provides a way to define custom types. Either internal or user types.
In some situations, this custom type may have to access the entity identifier.
Concrete use case: compute a custom value using the entity identifier (may be null depending on the id strategy which is used).
This is currently possible from the nullSafeGet method through the owner but this is not possible to access that identifier from the nullSafeSet Method.
So, the proposal would be to review the Hibernate internals to allow exposing this identifier as follow on the UserType interface and call this new method instead of the current one
{code:java}public interface UserType {
// hibernate would call this method internally
// id parameter is the owner/entity identifier
default void nullSafeSet(PreparedStatement st, Serializable id, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
nullSafeSet(st, value, index, session);
}
// may have a default implementation to allow choosing to override one or the other
void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException;
}{code}
Usage may be as follow
{noformat}public class MyType implements UserType {
@Override
void nullSafeSet(PreparedStatement st, Serializable id, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
// compute my new type using the owner/entity id
}
@Override
void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
// does nothing ... default implementation in the interface?
}
}{noformat}
The Type interface would also need to be updated the same way to allow transmitting the id from the caller stack. See CustomType.
Proposed change is retro-compatible.
( https://hibernate.atlassian.net/browse/HHH-16550#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16550#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
Prithvi singh ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *commented* on HHH-16489 ( https://hibernate.atlassian.net/browse/HHH-16489?atlOrigin=eyJpIjoiNjY4M2... )
Re: Hibernate native query returns duplicate column values with addScalar() call ( https://hibernate.atlassian.net/browse/HHH-16489?atlOrigin=eyJpIjoiNjY4M2... )
Hi @Puhong You, I tried to look into this issue and executed the above mentioned test case in version 5.6.15. Unfortunately, the test is not completing and I am getting org.hibernate.MappingException as java.lang.Integer class could not be recognised as an entity.
Here are the attached snippets. I am using maven as my build tool and h2 as my database.
My pom.xml
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion> 4.0.0 </modelVersion>
<groupId> org.example </groupId>
<artifactId> hibernate-tests </artifactId>
<version> 1.0-SNAPSHOT </version>
<packaging> jar </packaging>
<name> hibernate-tests </name>
<url> http://maven.apache.org </url>
<properties>
<project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding>
<maven.compiler.source> 17 </maven.compiler.source>
<maven.compiler.target> 17 </maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId> com.h2database </groupId>
<artifactId> h2 </artifactId>
<version> 2.1.214 </version>
<scope> test </scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId> org.hibernate </groupId>
<artifactId> hibernate-core </artifactId>
<version> 5.6.15.Final </version>
</dependency>
<dependency>
<groupId> junit </groupId>
<artifactId> junit </artifactId>
<version> 4.13.2 </version>
<scope> test </scope>
</dependency>
</dependencies>
</project>
package org.example;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
@Entity
public class DummyUser {
@Id
@Column(name = "USER_ID" )
@GenericGenerator( name = "dummyuser_increment" ,strategy = "increment" )
@GeneratedValue(generator = "dummyuser_increment" )
private int userId;
@Column(name = "USER_NAME" ,nullable = false )
private String userName;
public DummyUser() {
}
public int getUserId() {
return userId;
}
public void setUserId( int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName( String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "DummyUser{" +
"userId=" + userId +
", userName= '" + userName + ' \'' +
'}' ;
}
}
Here is my test file
package org.example;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.NativeQuery;
import org.hibernate.type.StandardBasicTypes;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class DummyUserTest {
private final SessionFactory sessionFactory;
public DummyUserTest() {
sessionFactory = new Configuration().configure().buildSessionFactory();
// also adding data to database
Session session=sessionFactory.openSession();
DummyUser dummyUser= new DummyUser();
dummyUser.setUserName( "Joe Doe" );
Transaction transaction= session.beginTransaction();
session.persist( dummyUser );
transaction.commit();
session.close();
}
@Test
public void checkUniquenessOfAddScalar() {
String sql= "SELECT user_id FROM dummyuser WHERE user_name= 'Joe Doe' " ;
// obtaining session
Session session=sessionFactory.openSession();
NativeQuery< Integer > query=session.createNativeQuery( sql, Integer.class );
query.addScalar( "user_id" , StandardBasicTypes.INTEGER );
List< Integer > rsList = query.list();
assertNotNull( rsList );
assertEquals( 1, rsList.size() );
assertEquals( Integer.valueOf( 1 ), rsList.get(0) );
}
}
And finally this is my surefire test report which shows the exception
-------------------------------------------------------------------------------
Test set: org.example.DummyUserTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.803 sec <<< FAILURE!
checkUniquenessOfAddScalar(org.example.DummyUserTest) Time elapsed: 1.75 sec <<< ERROR!
javax.persistence.PersistenceException: org.hibernate.MappingException: Unknown entity: java.lang.Integer
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1626)
at org.example.DummyUserTest.checkUniquenessOfAddScalar(DummyUserTest.java:41)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.hibernate.MappingException: Unknown entity: java.lang.Integer
at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:715)
at org.hibernate.engine.spi.SessionFactoryImplementor.getEntityPersister(SessionFactoryImplementor.java:360)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:445)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:498)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:465)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:180)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:74)
at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:44)
at org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:244)
at org.hibernate.internal.AbstractSharedSessionContract.getNativeQueryPlan(AbstractSharedSessionContract.java:640)
at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1204)
at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:177)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
... 33 more
@Puhog You could you please provide me snippets for a working test case in version 5.6.15 so that I may be able to better look into this issue.
( https://hibernate.atlassian.net/browse/HHH-16489#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16489#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )
Scott Marlow ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-16542 ( https://hibernate.atlassian.net/browse/HHH-16542?atlOrigin=eyJpIjoiNDVlM2... )
Re: (Jakarta EE 10 Platform TCK) jpa/core/entitytest/cascadeall/oneXone/cascadeAll1X1Test10 test regression ( https://hibernate.atlassian.net/browse/HHH-16542?atlOrigin=eyJpIjoiNDVlM2... )
private static void checkGetAndIsVariants(
Class containerClass, String propertyName, Method getMethod, Method isMethod) {
// Check the return types. If they are the same, its ok. If they are different // we are in a situation where we could not reasonably know which to use.
if ( !isMethod.getReturnType().equals( getMethod.getReturnType() ) ) {
throw new MappingException(
String.format(
Locale.ROOT, "In trying to locate getter for property [%s], Class [%s] defined " +
"both a `get` [%s] and `is` [%s] variant", propertyName, containerClass.getName(), getMethod.toString(), isMethod.toString()
)
); }
}
Mentioned ReflectHelper code is ^ and error is:
org.hibernate.MappingException: In trying to locate getter for property [b1] , Class [com.sun.ts.tests.jpa.core.entitytest.cascadeall.oneXone.A] defined both a get [public com.sun.ts.tests.jpa.core.entitytest.cascadeall.oneXone.B com.sun.ts.tests.jpa.core.entitytest.cascadeall.oneXone.A.getB1()] and is [public boolean com.sun.ts.tests.jpa.core.entitytest.cascadeall.oneXone.A.isB1()] variant
The offending TCK source code is:
@OneToOne(targetEntity = com.sun.ts.tests.jpa.core.entitytest.cascadeall.oneXone.B.class, mappedBy = "a1", orphanRemoval = true)
protected B b1;
public B getB1()
{ return b1; }
public boolean isB1()
{ TestUtil.logTrace("isB1"); if (getB1() != null) TestUtil.logTrace("Relationship to B is not null..."); else TestUtil.logTrace("Relationship for B is null ..."); return getB1() != null; }
Apologies for pasting all of the above but it helps me to see it all together as one comment. 🙂
From the above pasted code + error, I think the test would pass if both methods returned either B or boolean but is that only a Hibernate requirement or is that also Persistence Specification requirement?
Could ReflectHelper be enhanced to handle ^ differently in JPA_COMPLIANCE mode?
( https://hibernate.atlassian.net/browse/HHH-16542#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16542#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100224- sha1:4684446 )