[JIRA] (HHH-15658) Embeddable with more fields than the parent fails with Index out of Bounds
by Phil Haeusler (JIRA)
Phil Haeusler ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-15658 ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiNGU0OG... )
Re: Embeddable with more fields than the parent fails with Index out of Bounds ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiNGU0OG... )
Andrea, attached is a simple reproduction of this issue
@DomainModel(
annotatedClasses = HHH15658Test.Contact.class
)
public class HHH15658Test extends BaseCoreFunctionalTestCase {
@Override
protected Class [] getAnnotatedClasses() {
return new Class [] {
Contact.class
};
}
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
//configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, " true " );
}
@Test
public void hhh15658Test() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
Session s = openSession();
Transaction tx = s.beginTransaction();
final String sql = """
select {c.*}
from contact c
""";
var contacts = s.createNativeQuery(sql, Contact.class, "c" ).list();
tx.commit();
s.close();
}
@Entity(name = "Contact" )
public static class Contact
{
@Id
private Long id;
private Address address;
}
@Embeddable
public static class Address
{
private String city;
private String state;
private String country;
private String postcode;
}
}
Exception is
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at org.hibernate.persister.entity.SingleTableEntityPersister.getSubclassPropertyTableNumber(SingleTableEntityPersister.java:594)
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$selectFragment$6(AbstractEntityPersister.java:1881)
at org.hibernate.loader.ast.internal.LoaderSqlAstCreationState.visitFetches(LoaderSqlAstCreationState.java:118)
at org.hibernate.sql.results.graph.AbstractFetchParent.afterInitialize(AbstractFetchParent.java:32)
at org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl.<init>(EmbeddableFetchImpl.java:75)
at org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping.generateFetch(EmbeddedAttributeMapping.java:238)
at org.hibernate.sql.results.graph.FetchParent.generateFetchableFetch(FetchParent.java:105)
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$selectFragment$6(AbstractEntityPersister.java:1910)
at org.hibernate.loader.ast.internal.LoaderSqlAstCreationState.visitFetches(LoaderSqlAstCreationState.java:118)
at org.hibernate.sql.results.graph.AbstractFetchParent.afterInitialize(AbstractFetchParent.java:32)
at org.hibernate.sql.results.graph.entity.AbstractEntityResultGraphNode.afterInitialize(AbstractEntityResultGraphNode.java:100)
at org.hibernate.persister.entity.AbstractEntityPersister.createDomainResult(AbstractEntityPersister.java:1289)
at org.hibernate.persister.entity.AbstractEntityPersister.selectFragment(AbstractEntityPersister.java:1943)
at org.hibernate.query.sql.internal.SQLQueryParser.resolveProperties(SQLQueryParser.java:236)
at org.hibernate.query.sql.internal.SQLQueryParser.substituteBrackets(SQLQueryParser.java:159)
at org.hibernate.query.sql.internal.SQLQueryParser.process(SQLQueryParser.java:63)
at org.hibernate.query.sql.internal.NativeSelectQueryPlanImpl.<init>(NativeSelectQueryPlanImpl.java:53)
at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:39)
at org.hibernate.query.sql.internal.NativeQueryImpl.createQueryPlan(NativeQueryImpl.java:643)
at org.hibernate.query.sql.internal.NativeQueryImpl.lambda$resolveSelectQueryPlan$7(NativeQueryImpl.java:604)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveSelectQueryPlan(QueryInterpretationCacheStandardImpl.java:83)
at org.hibernate.query.sql.internal.NativeQueryImpl.resolveSelectQueryPlan(NativeQueryImpl.java:602)
at org.hibernate.query.sql.internal.NativeQueryImpl.doList(NativeQueryImpl.java:596)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
at org.hibernate.bugs.HHH15658Test.hhh15658Test(HHH15658Test.java:74)
( https://hibernate.atlassian.net/browse/HHH-15658#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15658#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#100210- sha1:4f8bc0d )
1 year, 10 months
[JIRA] (HHH-15683) Query.setLockOptions() ignores some of the options, apparently by design
by Gavin King (JIRA)
Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-15683 ( https://hibernate.atlassian.net/browse/HHH-15683?atlOrigin=eyJpIjoiYWEwMD... )
Re: Query.setLockOptions() ignores some of the options, apparently by design ( https://hibernate.atlassian.net/browse/HHH-15683?atlOrigin=eyJpIjoiYWEwMD... )
Aaahhh, wait, perhaps this is more of a documentation bug.
So apparently QuerySqmImpl overrides the inherited implementation of setLockOptions() , and, contrary to its documented semantics , does copy over the aliasSpecificLockModes , but only if at least one was set.
This is actually a bit fragile, and it’s not what I would do, but at least it’s not as crazy as what I described above.
( https://hibernate.atlassian.net/browse/HHH-15683#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15683#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#100210- sha1:4f8bc0d )
1 year, 10 months
[JIRA] (HHH-15658) Embeddable with more fields than the parent fails with Index out of Bounds
by Andrea Boriero (JIRA)
Andrea Boriero ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-15658 ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiMTEwNG... )
Re: Embeddable with more fields than the parent fails with Index out of Bounds ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiMTEwNG... )
Hi Phil Haeusler ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) ,
I have created this reproducer
@DomainModel(
annotatedClasses = EmbeddableTest.Person.class
)
@SessionFactory
public class EmbeddableTest {
@BeforeEach
public void setUp(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Address address = new Address( "Milan", "Italy", "Italy", "20133" );
Person person = new Person( 1, address );
Address address2 = new Address( "Garbagnate", "Italy", "Italy", "20024" );
Person person2 = new Person( 2, address2 );
session.persist( person );
session.persist( person2 );
}
);
}
@Test
public void testList(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List<Person> people = session.createQuery( "select p from Person p", Person.class )
.list();
assertThat( people.size() ).isEqualTo( 2 );
}
);
}
@Entity(name = "Person")
public static class Person {
@Id
private Integer id;
private Address address;
public Person() {
}
public Person(Integer id, Address address) {
this.id = id;
this.address = address;
}
}
@Embeddable
public static class Address {
private String city;
private String state;
private String country;
private String postcode;
public Address() {
}
public Address(String city, String state, String country, String postcode) {
this.city = city;
this.state = state;
this.country = country;
this.postcode = postcode;
}
}
}
but the test passes, am I missing anything?
can you please provide a reproducer?
Thanks
( https://hibernate.atlassian.net/browse/HHH-15658#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15658#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#100210- sha1:4f8bc0d )
1 year, 10 months