HHH-7203 - IdentityGenerator fails with JOINED Inheritance when inserting entity to PosgtreSQL
This commit is contained in:
parent
4450b127b2
commit
54f4335416
|
@ -99,7 +99,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
rs = insert.getGeneratedKeys();
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
rs,
|
||||
persister.getIdentifierColumnNames()[0],
|
||||
persister.getRootTableKeyColumnNames()[0],
|
||||
persister.getIdentifierType()
|
||||
);
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
try {
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
rs,
|
||||
persister.getIdentifierColumnNames()[0],
|
||||
persister.getRootTableKeyColumnNames()[0],
|
||||
persister.getIdentifierType()
|
||||
);
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
SessionImplementor session,
|
||||
ResultSet rs,
|
||||
Object object) throws SQLException {
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity( rs, null, persister.getIdentifierType() );
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity( rs, persister.getRootTableKeyColumnNames()[0], persister.getIdentifierType() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class SequenceIdentityGenerator
|
|||
insert.executeUpdate();
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
insert.getGeneratedKeys(),
|
||||
getPersister().getIdentifierColumnNames()[0],
|
||||
getPersister().getRootTableKeyColumnNames()[0],
|
||||
getPersister().getIdentifierType()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Andrey Vlasov
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialectFeature( DialectChecks.SupportsIdentityColumns.class )
|
||||
public class JoinedSubclassHierarchyWithIdentityGenerationTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Sub.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPersistDebtorAccountWhenParentServiceAgreementPersisted() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
s.save( new Sub() );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.createQuery( "delete Sub" ).executeUpdate();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
/**
|
||||
* @author Andrey Vlasov
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn(name = "super_id")
|
||||
public class Sub extends Super {
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
import static javax.persistence.GenerationType.IDENTITY;
|
||||
import static javax.persistence.InheritanceType.JOINED;
|
||||
|
||||
/**
|
||||
* @author Andrey Vlasov
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = JOINED)
|
||||
public class Super {
|
||||
@Id
|
||||
@GeneratedValue(strategy = IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
private Long value;
|
||||
}
|
Loading…
Reference in New Issue