[JIRA] (HHH-16096) Passing an ExtendedBeanManager which is notified too late leads to initialization error
by Vedran Prišćan (JIRA)
Vedran Prišćan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63d101b... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjVjYmY0ZWE2... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16096?atlOrigin=eyJpIjoiMjVjYm... ) HHH-16096 ( https://hibernate.atlassian.net/browse/HHH-16096?atlOrigin=eyJpIjoiMjVjYm... ) Passing an ExtendedBeanManager which is notified too late leads to initialization error ( https://hibernate.atlassian.net/browse/HHH-16096?atlOrigin=eyJpIjoiMjVjYm... )
Change By: Vedran Prišćan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63d101b... )
Hibernate cannot be successfully initialized in the following scenario:
* ExtendedBeanManager is used and is notified too late (for example on WildFly)
* custom _UserType_ that also implements _DynamicParameterizedType_ is used for entity column.
For example, _JsonBinaryType_ from _io.hypersistence.hypersistence-utils-hibernate-60_ does not work on WildFly. @Vlad Mihalcea
Cause: There is a missing null check for _BeanManager_ in _org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy.NamedBeanImpl.initialize_.
Note: _hibernate.query.startup_check=false_ and _hibernate.delay_cdi_access=true_ do not resolve the issue.
Stack trace when initialization fails:
{code: sh java }
mnc_standalone | Caused by: org.hibernate.resource.beans.container.internal.NotYetReadyException: CDI BeanManager not (yet) ready to use
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy$NamedBeanImpl.initialize(JpaCompliantLifecycleStrategy.java:231)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl$NamedBeanImpl.initialize(CdiBeanContainerExtendedAccessImpl.java:165)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl$NamedBeanImpl.getBeanInstance(CdiBeanContainerExtendedAccessImpl.java:172)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.resource.beans.internal.ManagedBeanRegistryImpl$ContainedBeanManagedBeanAdapter.getBeanInstance(ManagedBeanRegistryImpl.java:155)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.mapping.BasicValue.setExplicitCustomType(BasicValue.java:828)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.cfg.annotations.BasicValueBinder.fillSimpleValue(BasicValueBinder.java:1238)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.cfg.SetBasicValueTypeSecondPass.doSecondPass(SetBasicValueTypeSecondPass.java:26)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1782)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1729)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:300)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
mnc_standalone | at org.hibernate.jipijapa-hibernate6@27.0.1.Final//org.jboss.as.jpa.hibernate.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:45)
mnc_standalone | at org.jboss.as.jpa@27.0.1.Final//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:171)
mnc_standalone | ... 10 more
mnc_standalone | Caused by: java.lang.NullPointerException
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy$NamedBeanImpl.initialize(JpaCompliantLifecycleStrategy.java:228)
mnc_standalone | ... 23 more
{code}
In [HHH-14914|https://hibernate.atlassian.net/browse/HHH-14914] similar issue was resolved for UserTypes that don't implement DynamicParameterizedType by adding a null check in _JpaCompliantLifecycleStrategy.BeanImpl_.
Solution: add a null check for _BeanManager_ in _org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy.NamedBeanImpl.initialize_ and use fallback producer if null, equivalent to [HHH-14914|https://github.com/hibernate/hibernate-orm/commit/9fec060fe2c61...] commit.
( https://hibernate.atlassian.net/browse/HHH-16096#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16096#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#100214- sha1:3d33cb1 )
1 year, 7 months
[JIRA] (HHH-16096) Passing an ExtendedBeanManager which is notified too late leads to initialization error
by Vedran Prišćan (JIRA)
Vedran Prišćan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63d101b... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOTdiOGFmMmE2... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16096?atlOrigin=eyJpIjoiOTdiOG... ) HHH-16096 ( https://hibernate.atlassian.net/browse/HHH-16096?atlOrigin=eyJpIjoiOTdiOG... ) Passing an ExtendedBeanManager which is notified too late leads to initialization error ( https://hibernate.atlassian.net/browse/HHH-16096?atlOrigin=eyJpIjoiOTdiOG... )
Issue Type: Bug Affects Versions: 6.0.0, 6.1.6 Assignee: Vedran Prišćan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63d101b... ) Created: 25/Jan/2023 02:54 AM Priority: Major Reporter: Vedran Prišćan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63d101b... ) Original estimate: 0.5h Remaining Estimate: 0.5h
Hibernate cannot be successfully initialized in the following scenario:
* ExtendedBeanManager is used and is notified too late (for example on WildFly)
* custom UserType that also implements DynamicParameterizedType is used for entity column.
For example, JsonBinaryType from io.hypersistence.hypersistence-utils-hibernate-60 does not work on WildFly. @Vlad Mihalcea
Cause: There is a missing null check for BeanManager in org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy.NamedBeanImpl.initialize.
Note: hibernate.query.startup_check=false and hibernate.delay_cdi_access=true do not resolve the issue.
Stack trace when initialization fails:
mnc_standalone | Caused by: org.hibernate.resource.beans.container.internal.NotYetReadyException: CDI BeanManager not (yet) ready to use
mnc_standalone | at org.hibernate(a)6.1.5.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy $NamedBeanImpl.initialize(JpaCompliantLifecycleStrategy.java:231)
mnc_standalone | at org.hibernate(a)6.1.5.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl $NamedBeanImpl.initialize(CdiBeanContainerExtendedAccessImpl.java:165)
mnc_standalone | at org.hibernate(a)6.1.5.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl $NamedBeanImpl.getBeanInstance(CdiBeanContainerExtendedAccessImpl.java:172)
mnc_standalone | at org.hibernate(a)6.1.5.Final//org.hibernate.resource.beans.internal.ManagedBeanRegistryImpl $ContainedBeanManagedBeanAdapter.getBeanInstance(ManagedBeanRegistryImpl.java:155)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.mapping.BasicValue.setExplicitCustomType(BasicValue.java:828)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.cfg.annotations.BasicValueBinder.fillSimpleValue(BasicValueBinder.java:1238)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.cfg.SetBasicValueTypeSecondPass.doSecondPass(SetBasicValueTypeSecondPass.java:26)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1782)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1729)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:300)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350)
mnc_standalone | at org.hibernate@6.1.5.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
mnc_standalone | at org.hibernate.jipijapa-hibernate6@27.0.1.Final//org.jboss.as.jpa.hibernate.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:45)
mnc_standalone | at org.jboss.as.jpa(a)27.0.1.Final//org.jboss.as.jpa.service.PersistenceUnitServiceImpl $1 $1.run(PersistenceUnitServiceImpl.java:171)
mnc_standalone | ... 10 more
mnc_standalone | Caused by: java.lang.NullPointerException
mnc_standalone | at org.hibernate(a)6.1.5.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy $NamedBeanImpl.initialize(JpaCompliantLifecycleStrategy.java:228)
mnc_standalone | ... 23 more
In HHH-14914 ( https://hibernate.atlassian.net/browse/HHH-14914 ) similar issue was resolved for UserTypes that don't implement DynamicParameterizedType by adding a null check in JpaCompliantLifecycleStrategy.BeanImpl.
Solution: add a null check for BeanManager in org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy.NamedBeanImpl.initialize equivalent to HHH-14914 ( https://github.com/hibernate/hibernate-orm/commit/9fec060fe2c61881080b410... ) commit.
( https://hibernate.atlassian.net/browse/HHH-16096#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16096#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#100214- sha1:3d33cb1 )
1 year, 7 months
[JIRA] (HHH-16095) OptimisticLockType.NONE ignored
by MK (JIRA)
MK ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNWFmYWU2NjMy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16095?atlOrigin=eyJpIjoiNWFmYW... ) HHH-16095 ( https://hibernate.atlassian.net/browse/HHH-16095?atlOrigin=eyJpIjoiNWFmYW... ) OptimisticLockType.NONE ignored ( https://hibernate.atlassian.net/browse/HHH-16095?atlOrigin=eyJpIjoiNWFmYW... )
Issue Type: Bug Affects Versions: 6.1.6, 5.6.14 Assignee: Unassigned Attachments: hibernate-test-case-optimistic-locking.zip Components: hibernate-core Created: 25/Jan/2023 02:24 AM Priority: Major Reporter: MK ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... )
After a discussion ( https://discourse.hibernate.org/t/optimisticlocktype-none-ignored-or-not-... ) beikov asked me to create a Jira issue:
The documentation states the following for the OptimisticLockType:
>
>
>
> NONE
> optimistic locking is disabled even if there is a @Version annotation
> present
>
>
I assumed that means that by default no exception should be thrown when merging a stale object, but it seems the OptimisticLockType.NONE is ignored and a StaleObjectStateException is thrown anyway.
I have created a reproducer using your test example and attached it to the issue.
Here is the code as well:
package org.hibernate.bugs.entities;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Version;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.OptimisticLocking;
@Entity
@OptimisticLocking(type = OptimisticLockType.NONE)
public class Example {
@Id
@GeneratedValue
private Long id;
private String name;
@Version
private Long rowVersion;
public Long getId() {
return id;
}
public void setId( Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName( String name) {
this.name = name;
}
public Long getRowVersion() {
return rowVersion;
}
public void setRowVersion( Long rowVersion) {
this.rowVersion = rowVersion;
}
}
package org.hibernate.bugs;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import org.hibernate.bugs.entities.Example;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
*/
public class JPAUnitTestCase {
private EntityManagerFactory entityManagerFactory;
@Before
public void init() {
entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );
}
@After
public void destroy() {
entityManagerFactory.close();
}
// Entities are auto-discovered, so just add them anywhere on class- path
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
// Transaction 1 - create entity
entityManager.getTransaction().begin();
// Create new entity
Example example = new Example();
example.setName( "Example1" );
entityManager.persist(example);
Long exampleId = example.getId();
entityManager.getTransaction().commit();
entityManager.close();
entityManager = entityManagerFactory.createEntityManager();
// Transaction 2 - update entity
entityManager.getTransaction().begin();
Example example2 = entityManager.find(Example.class, exampleId);
example2.setName( "Example2" );
entityManager.merge(example2);
entityManager.getTransaction().commit();
entityManager.close();
entityManager = entityManagerFactory.createEntityManager();
// Transaction 3 - update stale entity
entityManager.getTransaction().begin();
example.setName( "Example3" );
// This should not throw a StaleObjectStateException but does
entityManager.merge(example);
entityManager.getTransaction().commit();
entityManager.close();
}
}
( https://hibernate.atlassian.net/browse/HHH-16095#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16095#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#100214- sha1:3d33cb1 )
1 year, 7 months
[JIRA] (HHH-16094) Default CLOB length in MySQL set to 255.
by florian576 (JIRA)
florian576 ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiY2FjNGUwNDg5... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16094?atlOrigin=eyJpIjoiY2FjNG... ) HHH-16094 ( https://hibernate.atlassian.net/browse/HHH-16094?atlOrigin=eyJpIjoiY2FjNG... ) Default CLOB length in MySQL set to 255. ( https://hibernate.atlassian.net/browse/HHH-16094?atlOrigin=eyJpIjoiY2FjNG... )
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Unassigned Attachments: hibernate.zip Components: hibernate-orm-modules Created: 25/Jan/2023 01:23 AM Priority: Major Reporter: florian576 ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
After migrating from Hibernate 5.6.14 to 6.1.6, I am encountering a schema validation error:
Exception in thread "main" org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [name] in table [Foo]; found [longtext (Types#LONGVARCHAR)], but expecting [tinytext (Types#CLOB)]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateColumnType(AbstractSchemaValidator.java:179)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:151)
at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:46)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:96)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:74)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:65)
at org.example.Main.validateSchema(Main.java:37)
at org.example.Main.main(Main.java:13)
I reproduced the bug with the example below (for more convenience, I also zipped and attached the project).
It requires a table in MySQL:
CREATE TABLE foodb.Foo (id INT , name LONGTEXT );
pom.xml:
<?xml version= "1.0" encoding= "UTF-8" ?>
<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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion> 4.0.0 </modelVersion>
<groupId> org.example </groupId>
<artifactId> hibernate5 </artifactId>
<version> 1.0-SNAPSHOT </version>
<dependencies>
<!--<dependency>
<groupId> org.hibernate </groupId>
<artifactId> hibernate-core </artifactId>
<version> 5.6.14.Final </version>
</dependency> -->
<dependency>
<groupId> org.hibernate.orm </groupId>
<artifactId> hibernate-core </artifactId>
<version> 6.1.6.Final </version>
</dependency>
<dependency>
<groupId> org.hibernate.orm </groupId>
<artifactId> hibernate-ant </artifactId>
<version> 6.1.6.Final </version>
</dependency>
<dependency>
<groupId> mysql </groupId>
<artifactId> mysql-connector-java </artifactId>
<version> 8.0.32 </version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source> 11 </maven.compiler.source>
<maven.compiler.target> 11 </maven.compiler.target>
<project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding>
</properties>
</project>
Foo.java
package org.example;
/* import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;*/
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
@Entity
@Table(name = "Foo" )
public class Foo {
@Id
private int id;
@Lob
private String name;
public int getId() {
return id;
}
public void setId( int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName( String name) {
this.name = name;
}
}
Main.java:
package org.example;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.tool.hbm2ddl.SchemaValidator;
import java.util.Map;
public class Main {
public static void main( String [] args) {
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(
Map.of(
"hibernate.connection.driver_class" , "com.mysql.jdbc.Driver" ,
"hibernate.dialect" , "org.hibernate.dialect.MySQL8Dialect" ,
"hibernate.connection.url" , "jdbc:mysql: //localhost/foodb" ,
"hibernate.connection.username" , "admin" ,
"hibernate.connection.password" , "admin" ,
"hibernate.default_schema" , "foodb"
)
)
.build();
Metadata metadata = new MetadataSources(serviceRegistry)
.addAnnotatedClass(Foo.class)
.buildMetadata();
new SchemaValidator().validate(metadata, serviceRegistry);
}
}
( https://hibernate.atlassian.net/browse/HHH-16094#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16094#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#100214- sha1:3d33cb1 )
1 year, 7 months