Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier generation - No part of a composite identifier may be null HibernateException
I spent the whole day tracking down / debugging / updating the org.hibernate.dialect.SQLServer2012Dialect and associated functions. I will continue tomorrow. On a side note SQL Server does not allow the identity column to be specified in the insert. As such the insert SQL statements generated by EntityIdentityInsertAction are bad, resulting in a com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table X when IDENTITY_INSERT is set to OFF. > -Original Message- > From: hibernate-dev-boun...@lists.jboss.org > On Behalf Of Jason > Pyeron > Sent: Tuesday, April 21, 2020 1:18 PM > To: 'Hibernate Dev' > Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier > generation - No part of a > composite identifier may be null HibernateException > > I have been reviewing the change set, I see where Fabio was going. This looks > like it will address the > Identify vs Sequence issue. That will still leave the > IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller not handling the > generation like the > NormalMappedIdentifierValueMarshaller does. > > > > Stack trace when using @Id Long id2: > > > > EmbeddedComponentType(ComponentType).instantiate(EntityMode) line: 587 > > AbstractEntityTuplizer$NormalMappedIdentifierValueMarshaller.getIdentifier(Object, > EntityMode, > SharedSessionContractImplementor) line: 322 > > PojoEntityTuplizer(AbstractEntityTuplizer).getIdentifier(Object, > SharedSessionContractImplementor) > line: 219 > > > > Stack trace when using @Id @ManyToOne SomeEntity id2: > > > > AbstractEntityTuplizer$IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller.getIdentifier(Object, > EntityMode, SharedSessionContractImplementor) line: 365 > > AbstractEntityTuplizer$IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller.getIdentifier(Object, > EntityMode, SharedSessionContractImplementor) line: 364 > > PojoEntityTuplizer(AbstractEntityTuplizer).getIdentifier(Object, > SharedSessionContractImplementor) > line: 219 > > > > -Jason > > > > > > From: andrea boriero > Sent: Tuesday, April 21, 2020 12:20 PM > To: Jason Pyeron > Cc: Hibernate Dev > Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier > generation - No part of a > composite identifier may be null HibernateException > > > > there is a PR related to this issue ( > https://github.com/hibernate/hibernate-orm/pull/3105), you can > try to verify if it solves the problem > > > > On Tue, 21 Apr 2020 at 16:15, Jason Pyeron <mailto:jpye...@pdinc.us> > wrote: > > How can I help on HHH-9662 ? > > I have found that this fails with sequences too, when the composite > identifier is another entity. > > This works: > @Id > @Column(name = "registration_number") > @GeneratedValue(strategy = GenerationType.SEQUENCE) > private Long registrationNumber; > > @Id > @Column(name = "publisher_id") > private Integer publisherId; > > but, this does not: > > @Id > @Column(name = "registration_number") > @GeneratedValue(strategy = GenerationType.SEQUENCE) > private Long registrationNumber; > > @Id > @JoinColumn(name = "publisher_id") > @ManyToOne > private Publisher publisherId; > > -Jason > > > > -Original Message- > > From: hibernate-dev-boun...@lists.jboss.org > > <mailto:hibernate-dev-boun...@lists.jboss.org> > [mailto:hibernate-dev-boun...@lists.jboss.org > <mailto:hibernate-dev-boun...@lists.jboss.org> ] > > On Behalf Of Jason Pyeron > > Sent: Tuesday, April 21, 2020 9:23 AM > > To: hibernate-us...@lists.jboss.org > > <mailto:hibernate-us...@lists.jboss.org> ; hibernate- > d...@lists.jboss.org <mailto:hibernate-dev@lists.jboss.org> > > Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier > > generation - No > > part of a composite identifier may be null HibernateException > > > > Turns out this issue may be a duplicate of a known issue, taking this over > > to the dev > > list. > > > > > > > > org/hibernate/test/annotations/cid/CompositeIdIdentityTest.java: > > > > 7 package org.hibernate.test.annotations.cid; > > > > 48 @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) > > > > 49 @TestForIssue( jiraKey = "HHH-9662" ) > > > > 50 public class CompositeIdIdentityTest extends > > BaseCoreFunctionalTestCase { > &g
Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier generation - No part of a composite identifier may be null HibernateException
I have been reviewing the change set, I see where Fabio was going. This looks like it will address the Identify vs Sequence issue. That will still leave the IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller not handling the generation like the NormalMappedIdentifierValueMarshaller does. Stack trace when using @Id Long id2: EmbeddedComponentType(ComponentType).instantiate(EntityMode) line: 587 AbstractEntityTuplizer$NormalMappedIdentifierValueMarshaller.getIdentifier(Object, EntityMode, SharedSessionContractImplementor) line: 322 PojoEntityTuplizer(AbstractEntityTuplizer).getIdentifier(Object, SharedSessionContractImplementor) line: 219 Stack trace when using @Id @ManyToOne SomeEntity id2: AbstractEntityTuplizer$IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller.getIdentifier(Object, EntityMode, SharedSessionContractImplementor) line: 365 AbstractEntityTuplizer$IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller.getIdentifier(Object, EntityMode, SharedSessionContractImplementor) line: 364 PojoEntityTuplizer(AbstractEntityTuplizer).getIdentifier(Object, SharedSessionContractImplementor) line: 219 -Jason From: andrea boriero Sent: Tuesday, April 21, 2020 12:20 PM To: Jason Pyeron Cc: Hibernate Dev Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier generation - No part of a composite identifier may be null HibernateException there is a PR related to this issue ( https://github.com/hibernate/hibernate-orm/pull/3105), you can try to verify if it solves the problem On Tue, 21 Apr 2020 at 16:15, Jason Pyeron mailto:jpye...@pdinc.us> > wrote: How can I help on HHH-9662 ? I have found that this fails with sequences too, when the composite identifier is another entity. This works: @Id @Column(name = "registration_number") @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long registrationNumber; @Id @Column(name = "publisher_id") private Integer publisherId; but, this does not: @Id @Column(name = "registration_number") @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long registrationNumber; @Id @JoinColumn(name = "publisher_id") @ManyToOne private Publisher publisherId; -Jason > -Original Message- > From: hibernate-dev-boun...@lists.jboss.org > <mailto:hibernate-dev-boun...@lists.jboss.org> > [mailto:hibernate-dev-boun...@lists.jboss.org > <mailto:hibernate-dev-boun...@lists.jboss.org> ] > On Behalf Of Jason Pyeron > Sent: Tuesday, April 21, 2020 9:23 AM > To: hibernate-us...@lists.jboss.org <mailto:hibernate-us...@lists.jboss.org> > ; hibernate-dev@lists.jboss.org <mailto:hibernate-dev@lists.jboss.org> > Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier > generation - No > part of a composite identifier may be null HibernateException > > Turns out this issue may be a duplicate of a known issue, taking this over to > the dev > list. > > > > org/hibernate/test/annotations/cid/CompositeIdIdentityTest.java: > > 7 package org.hibernate.test.annotations.cid; > > 48 @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) > > 49 @TestForIssue( jiraKey = "HHH-9662" ) > > 50 public class CompositeIdIdentityTest extends > BaseCoreFunctionalTestCase { > > 51 > > 52 @Test > > 53 @FailureExpected( jiraKey = "HHH-9662" ) > > 54 public void testCompositePkWithIdentity() throws Exception { > > 55 doInHibernate( this::sessionFactory, session -> { > > 56 Animal animal = new Animal(); > > 57 animal.setSubId( 123L ); > > 58 session.persist(animal); > > 59 } ); > > 60 } > > 61 > > 70 @Entity > > 71 @Table(name = "animal") > > 72 @IdClass(IdWithSubId.class) > > 73 public static class Animal { > > 74 > > 75 @Id > > 76 @GeneratedValue(strategy = GenerationType.IDENTITY) > > 77 private Long id; > > 78 > > 79 @Id > > 80 @Column(name = "sub_id") > > 81 private Long subId; > > 82 > > > > > > From: Jason Pyeron [mailto:jpye...@pdinc.us <mailto:jpye...@pdinc.us> ] > Sent: Tuesday, April 21, 2020 1:32 AM > To: 'hibernate-us...@lists.jboss.org <mailto:hibernate-us...@lists.jboss.org> > ' mailto:hiber
Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier generation - No part of a composite identifier may be null HibernateException
there is a PR related to this issue ( https://github.com/hibernate/hibernate-orm/pull/3105), you can try to verify if it solves the problem On Tue, 21 Apr 2020 at 16:15, Jason Pyeron wrote: > How can I help on HHH-9662 ? > > I have found that this fails with sequences too, when the composite > identifier is another entity. > > This works: > @Id > @Column(name = "registration_number") > @GeneratedValue(strategy = GenerationType.SEQUENCE) > private Long registrationNumber; > > @Id > @Column(name = "publisher_id") > private Integer publisherId; > > but, this does not: > > @Id > @Column(name = "registration_number") > @GeneratedValue(strategy = GenerationType.SEQUENCE) > private Long registrationNumber; > > @Id > @JoinColumn(name = "publisher_id") > @ManyToOne > private Publisher publisherId; > > -Jason > > > > -Original Message- > > From: hibernate-dev-boun...@lists.jboss.org [mailto: > hibernate-dev-boun...@lists.jboss.org] > > On Behalf Of Jason Pyeron > > Sent: Tuesday, April 21, 2020 9:23 AM > > To: hibernate-us...@lists.jboss.org; hibernate-dev@lists.jboss.org > > Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier > generation - No > > part of a composite identifier may be null HibernateException > > > > Turns out this issue may be a duplicate of a known issue, taking this > over to the dev > > list. > > > > > > > > org/hibernate/test/annotations/cid/CompositeIdIdentityTest.java: > > > > 7 package org.hibernate.test.annotations.cid; > > > > 48 > @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) > > > > 49 @TestForIssue( jiraKey = "HHH-9662" ) > > > > 50 public class CompositeIdIdentityTest extends > BaseCoreFunctionalTestCase { > > > > 51 > > > > 52 @Test > > > > 53 @FailureExpected( jiraKey = "HHH-9662" ) > > > > 54 public void testCompositePkWithIdentity() throws > Exception { > > > > 55 doInHibernate( this::sessionFactory, session -> { > > > > 56 Animal animal = new Animal(); > > > > 57 animal.setSubId( 123L ); > > > > 58 session.persist(animal); > > > > 59 } ); > > > > 60 } > > > > 61 > > > > 70 @Entity > > > > 71 @Table(name = "animal") > > > > 72 @IdClass(IdWithSubId.class) > > > > 73 public static class Animal { > > > > 74 > > > > 75 @Id > > > > 76 @GeneratedValue(strategy = > GenerationType.IDENTITY) > > > > 77 private Long id; > > > > 78 > > > > 79 @Id > > > > 80 @Column(name = "sub_id") > > > > 81 private Long subId; > > > > 82 > > > > > > > > > > > > From: Jason Pyeron [mailto:jpye...@pdinc.us] > > Sent: Tuesday, April 21, 2020 1:32 AM > > To: 'hibernate-us...@lists.jboss.org' > > Subject: HHH-6044 and partial identifier generation - No part of a > composite identifier > > may be null HibernateException > > > > > > > > [note this is an issue with sequences too] > > > > > > > > Quoting > > > https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#i > > dentifiers-composite-nonaggregated > > > > With non-aggregated composite identifiers, Hibernate also supports > "partial" generation of > > the composite values. > > > > Example 135. @IdClass with partial identifier generation using > @GeneratedValue > > > > > > > > I seem to be having the same issues as > https://hibernate.atlassian.net/browse/HHH-6044 > > > > > > > > I have existing tables / Entities (simplified): > > > > > > > > CREATE TABLE [cresaptown].[saar]( > > > >[id] [bigint] IDENTITY(1,1) NOT NULL primary key > > > > ); > > > > > > > > @Entity > > > > @Table(schema = "cresaptown", name = "saar") > > > > public class SystemAccess
Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier generation - No part of a composite identifier may be null HibernateException
How can I help on HHH-9662 ? I have found that this fails with sequences too, when the composite identifier is another entity. This works: @Id @Column(name = "registration_number") @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long registrationNumber; @Id @Column(name = "publisher_id") private Integer publisherId; but, this does not: @Id @Column(name = "registration_number") @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long registrationNumber; @Id @JoinColumn(name = "publisher_id") @ManyToOne private Publisher publisherId; -Jason > -Original Message- > From: hibernate-dev-boun...@lists.jboss.org > [mailto:hibernate-dev-boun...@lists.jboss.org] > On Behalf Of Jason Pyeron > Sent: Tuesday, April 21, 2020 9:23 AM > To: hibernate-us...@lists.jboss.org; hibernate-dev@lists.jboss.org > Subject: Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier > generation - No > part of a composite identifier may be null HibernateException > > Turns out this issue may be a duplicate of a known issue, taking this over to > the dev > list. > > > > org/hibernate/test/annotations/cid/CompositeIdIdentityTest.java: > > 7 package org.hibernate.test.annotations.cid; > > 48 @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) > > 49 @TestForIssue( jiraKey = "HHH-9662" ) > > 50 public class CompositeIdIdentityTest extends > BaseCoreFunctionalTestCase { > > 51 > > 52 @Test > > 53 @FailureExpected( jiraKey = "HHH-9662" ) > > 54 public void testCompositePkWithIdentity() throws Exception { > > 55 doInHibernate( this::sessionFactory, session -> { > > 56 Animal animal = new Animal(); > > 57 animal.setSubId( 123L ); > > 58 session.persist(animal); > > 59 } ); > > 60 } > > 61 > > 70 @Entity > > 71 @Table(name = "animal") > > 72 @IdClass(IdWithSubId.class) > > 73 public static class Animal { > > 74 > > 75 @Id > > 76 @GeneratedValue(strategy = GenerationType.IDENTITY) > > 77 private Long id; > > 78 > > 79 @Id > > 80 @Column(name = "sub_id") > > 81 private Long subId; > > 82 > > > > > > From: Jason Pyeron [mailto:jpye...@pdinc.us] > Sent: Tuesday, April 21, 2020 1:32 AM > To: 'hibernate-us...@lists.jboss.org' > Subject: HHH-6044 and partial identifier generation - No part of a composite > identifier > may be null HibernateException > > > > [note this is an issue with sequences too] > > > > Quoting > https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#i > dentifiers-composite-nonaggregated > > With non-aggregated composite identifiers, Hibernate also supports "partial" > generation of > the composite values. > > Example 135. @IdClass with partial identifier generation using @GeneratedValue > > > > I seem to be having the same issues as > https://hibernate.atlassian.net/browse/HHH-6044 > > > > I have existing tables / Entities (simplified): > > > > CREATE TABLE [cresaptown].[saar]( > >[id] [bigint] IDENTITY(1,1) NOT NULL primary key > > ); > > > > @Entity > > @Table(schema = "cresaptown", name = "saar") > > public class SystemAccessAuthorizationRequest > > { > > @Id > > @GeneratedValue > > Long id; > > } > > > > CREATE TABLE [cresaptown].[signature]( > >[rid] [bigint] IDENTITY(1,1) NOT NULL, > >[sid] [bigint] NOT NULL, > >PRIMARY KEY ([rid],[sid]), > >FOREIGN KEY([rid]) REFERENCES [cresaptown].[saar] ([id]) > > ); > > > > @Entity > > @Table(schema = "cresaptown", name = "signature") > > @IdClass(Signature.ID.class) > > public class Signature > > { > > @Id > > @Column(name = "sid") > > @GeneratedValue > > Long sid; > > > > @Id > > @JoinColumn(name = "rid") > > @ManyToOne > > SystemAccessAuthorizationRequest rid; >
Re: [hibernate-dev] HHH-6044 / HHH-9662 and partial identifier generation - No part of a composite identifier may be null HibernateException
Turns out this issue may be a duplicate of a known issue, taking this over to the dev list. org/hibernate/test/annotations/cid/CompositeIdIdentityTest.java: 7 package org.hibernate.test.annotations.cid; 48 @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) 49 @TestForIssue( jiraKey = "HHH-9662" ) 50 public class CompositeIdIdentityTest extends BaseCoreFunctionalTestCase { 51 52 @Test 53 @FailureExpected( jiraKey = "HHH-9662" ) 54 public void testCompositePkWithIdentity() throws Exception { 55 doInHibernate( this::sessionFactory, session -> { 56 Animal animal = new Animal(); 57 animal.setSubId( 123L ); 58 session.persist(animal); 59 } ); 60 } 61 70 @Entity 71 @Table(name = "animal") 72 @IdClass(IdWithSubId.class) 73 public static class Animal { 74 75 @Id 76 @GeneratedValue(strategy = GenerationType.IDENTITY) 77 private Long id; 78 79 @Id 80 @Column(name = "sub_id") 81 private Long subId; 82 From: Jason Pyeron [mailto:jpye...@pdinc.us] Sent: Tuesday, April 21, 2020 1:32 AM To: 'hibernate-us...@lists.jboss.org' Subject: HHH-6044 and partial identifier generation - No part of a composite identifier may be null HibernateException [note this is an issue with sequences too] Quoting https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#identifiers-composite-nonaggregated With non-aggregated composite identifiers, Hibernate also supports "partial" generation of the composite values. Example 135. @IdClass with partial identifier generation using @GeneratedValue I seem to be having the same issues as https://hibernate.atlassian.net/browse/HHH-6044 I have existing tables / Entities (simplified): CREATE TABLE [cresaptown].[saar]( [id] [bigint] IDENTITY(1,1) NOT NULL primary key ); @Entity @Table(schema = "cresaptown", name = "saar") public class SystemAccessAuthorizationRequest { @Id @GeneratedValue Long id; } CREATE TABLE [cresaptown].[signature]( [rid] [bigint] IDENTITY(1,1) NOT NULL, [sid] [bigint] NOT NULL, PRIMARY KEY ([rid],[sid]), FOREIGN KEY([rid]) REFERENCES [cresaptown].[saar] ([id]) ); @Entity @Table(schema = "cresaptown", name = "signature") @IdClass(Signature.ID.class) public class Signature { @Id @Column(name = "sid") @GeneratedValue Long sid; @Id @JoinColumn(name = "rid") @ManyToOne SystemAccessAuthorizationRequest rid; public static class ID implements Serializable { Long sid; Long rid; } } A code fragment em.getTransaction().begin(); SystemAccessAuthorizationRequest saar = new SystemAccessAuthorizationRequest(); em.persist(saar); Signature sig = new Signature(); sig.setRid(saar); em.persist(sig); em.getTransaction().commit(); gives this exception, but if I disable the null check in AbstractEntityTuplizer.getIdentifier, I get the same issue as in HHH-6044 javax.persistence.PersistenceException: org.hibernate.HibernateException: No part of a composite identifier may be null at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:716) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:696) at x.Testclass.x(Testclass.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)