Skip to content

HHH-19372: Reproducing test #10056

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

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.optimizer;

import org.hibernate.orm.test.bytecode.enhancement.optimizer.child.ChildEntity;
import org.hibernate.query.Query;

import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

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

@DomainModel(annotatedClasses = {
ParentEntity.class,
ChildEntity.class,
})
@SessionFactory
@Jira( "https://hibernate.atlassian.net/browse/HHH-19059" )
@BytecodeEnhanced
public class HierarchyBytecodeOptimizerTest {

@Test
public void testOptimizerSetPropertyValues(SessionFactoryScope scope) {
ChildEntity childEntity = new ChildEntity();
childEntity.setId( 1L );
childEntity.setField( "field" );
childEntity.setChieldField( "childField" );

scope.inTransaction( session -> session.persist( childEntity ) );

scope.inTransaction( session -> {
Query<ChildEntity> query = session.createQuery( "select c from ChildEntity c where c.field = :field", ChildEntity.class);
query.setParameter( "field", "field" );
assertThat( query.uniqueResult() ).isNotNull();
} );
}

@AfterAll
public void cleanup(SessionFactoryScope scope) {
scope.getSessionFactory().getSchemaManager().truncateMappedObjects();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.optimizer;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;

@Entity(name = "ParentEntity")
@Inheritance(strategy = InheritanceType.JOINED)
public class ParentEntity {
@Id
private Long id;

private String field;

public Long getId() {
return id;
}

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

public String getField() {
return field;
}

public void setField(String field) {
this.field = field;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.optimizer.child;

import org.hibernate.orm.test.bytecode.enhancement.optimizer.ParentEntity;

import jakarta.persistence.Entity;

@Entity(name = "ChildEntity")
public class ChildEntity extends ParentEntity {
private String childField;

public String getChildField() {
return childField;
}

public void setChieldField(String childField) {
this.childField = childField;
}
}