From 5c16c01064f4e2970860c5da47d0f0425aefac02 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 5 Feb 2010 18:28:39 +0000 Subject: [PATCH] HHH-4884 - Fix binding of @TableGenerator#initialValue into org.hibernate.id.enhanced.TableGenerator git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18704 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../org/hibernate/cfg/AnnotationBinder.java | 3 +- .../hibernate/test/annotations/id/IdTest.java | 6 +++ .../test/annotations/id/NewSchemeIdTest.java | 39 +++++++++++++++++++ .../test/annotations/id/sequences/IdTest.java | 7 ++++ .../id/sequences/NewSchemeIdTest.java | 39 +++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 annotations/src/test/java/org/hibernate/test/annotations/id/NewSchemeIdTest.java create mode 100644 annotations/src/test/java/org/hibernate/test/annotations/id/sequences/NewSchemeIdTest.java diff --git a/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java index d440ca154e..6915c61382 100644 --- a/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -387,7 +387,8 @@ public final class idGen.addParam( org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, tabGen.valueColumnName() ); } idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM, String.valueOf( tabGen.allocationSize() ) ); - idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM, String.valueOf( tabGen.initialValue() ) ); + // See comment on HHH-4884 wrt initialValue. Basically initialValue is really the stated value + 1 + idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM, String.valueOf( tabGen.initialValue() + 1 ) ); if ( tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length > 0 ) { log.warn( "Ignoring unique constraints specified on table generator [{}]", tabGen.name() ); } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/id/IdTest.java b/annotations/src/test/java/org/hibernate/test/annotations/id/IdTest.java index 939363a69c..0c2bfb5173 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/id/IdTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/id/IdTest.java @@ -3,6 +3,8 @@ package org.hibernate.test.annotations.id; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.cfg.Configuration; import org.hibernate.mapping.Column; import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.id.entities.Ball; @@ -298,4 +300,8 @@ public class IdTest extends TestCase { return new String[] { "org/hibernate/test/annotations/orm.xml" }; } + @Override + protected void configure(Configuration cfg) { + cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); + } } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/id/NewSchemeIdTest.java b/annotations/src/test/java/org/hibernate/test/annotations/id/NewSchemeIdTest.java new file mode 100644 index 0000000000..48c397dcd3 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/id/NewSchemeIdTest.java @@ -0,0 +1,39 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, 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.annotations.id; + +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.cfg.Configuration; + +/** + * TODO : javadoc + * + * @author Steve Ebersole + */ +public class NewSchemeIdTest extends IdTest { + @Override + protected void configure(Configuration cfg) { + cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); + } +} diff --git a/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java b/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java index 9445b68f32..85d13d0d7a 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java @@ -3,6 +3,8 @@ package org.hibernate.test.annotations.id.sequences; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.cfg.Configuration; import org.hibernate.mapping.Column; import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.id.sequences.entities.Ball; @@ -305,4 +307,9 @@ public class IdTest extends TestCase { return new String[] { "org/hibernate/test/annotations/orm.xml" }; } + @Override + protected void configure(Configuration cfg) { + cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); + } + } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/NewSchemeIdTest.java b/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/NewSchemeIdTest.java new file mode 100644 index 0000000000..3215adcf09 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/NewSchemeIdTest.java @@ -0,0 +1,39 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, 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.annotations.id.sequences; + +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.cfg.Configuration; + +/** + * TODO : javadoc + * + * @author Steve Ebersole + */ +public class NewSchemeIdTest extends IdTest { + @Override + protected void configure(Configuration cfg) { + cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); + } +} \ No newline at end of file