&& table.getIdentifierValue().isIdentityColumn( metadata.getIdentifierGeneratorFactory(), dialect );
@Test public void testImplicitTableGenerator() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ImplicitTableGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitTableGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator ); assertThat( tableGenerator.getTableName(), is( "my_id_table" ) ); // all the JPA defaults since they were not defined assertThat( tableGenerator.getInitialValue(), is( 1 ) ); assertThat( tableGenerator.getIncrementSize(), is( 50 ) ); }
@Test public void testExplicitTableGeneratorImplicitName() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ExplicitTableGeneratorImplicitNameEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorImplicitNameEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator ); assertThat( tableGenerator.getTableName(), is( "my_id_table" ) ); // - note : currently initialValue=1 in mapping is shows up here as 2 assertThat( tableGenerator.getInitialValue(), is( 1 ) ); assertThat( tableGenerator.getIncrementSize(), is( 25 ) ); }
@Test public void testImplicitSequenceGenerator() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false" ) .build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ImplicitSequenceGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator ); // PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy // default (hibernate_sequence) should be used assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "hibernate_sequence" ) ); // the JPA defaults since they were not defined assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) ); }
@Test public void baseline() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ExplicitGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_real_db_sequence" ) ); // all the JPA defaults since they were not defined assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) ); }
@Test public void testExplicitSequenceGeneratorImplicitName() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false" ) .build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ExplicitSequenceGeneratorImplicitNameEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitSequenceGeneratorImplicitNameEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator ); // all the JPA defaults since they were not defined assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( SequenceStyleGenerator.DEF_SEQUENCE_NAME ) ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) ); }
@Test public void testExplicitTableGenerator() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ExplicitTableGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator ); assertThat( tableGenerator.getTableName(), is( "my_real_id_table" ) ); // all the JPA defaults since they were not defined // - note : currently initialValue=1 in mapping is shows up here // as 2 // assertThat( tableGenerator.getInitialValue(), is( 1 ) ); assertThat( tableGenerator.getIncrementSize(), is( 25 ) ); }
@Test public void testImplicitSequenceGeneratorGeneratorName() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ImplicitSequenceGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator ); // PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == true (the default) indicates that the generator-name // should be used as the default instead. assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) ); // the JPA defaults since they were not defined assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) ); }
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitSequenceGeneratorImplicitNameEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null,
@Test public void testIdentifierGeneratorExtendsIdentityGenerator() { final MetadataSources sources = new MetadataSources( serviceRegistry() ); sources.addAnnotatedClass( EntityBean.class ); final MetadataBuilder builder = sources.getMetadataBuilder(); final Metadata metadata = builder.build(); for ( final Namespace ns : metadata.getDatabase().getNamespaces() ) { for ( final org.hibernate.mapping.Table table : ns.getTables() ) { final KeyValue value = table.getIdentifierValue(); assertNotNull( "IdentifierValue was null", value ); assertTrue( value.isIdentityColumn( metadata.getIdentifierGeneratorFactory(), getDialect() ) ); } } Session s = openSession(); s.beginTransaction(); s.save( new EntityBean() ); s.getTransaction().commit(); s.close(); } }
assertEquals( UUID.class, entityBinding.getIdentifier().getType().getReturnedClass() ); IdentifierGenerator generator = entityBinding.getIdentifier().createIdentifierGenerator( metadata.getIdentifierGeneratorFactory(), metadata.getDatabase().getDialect(), null,
@Test public void testExplicitIncrementGenerator() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ExplicitIncrementGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); assertTyping( IncrementGenerator.class, generator ); }
@Test public void testImplicitIncrementGenerator() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); final Metadata bootModel = new MetadataSources( ssr ) .addAnnotatedClass( ImplicitIncrementGeneratorEntity.class ) .buildMetadata(); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() ); final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( bootModel.getIdentifierGeneratorFactory(), ssr.getService( JdbcEnvironment.class ).getDialect(), null, null, (RootClass) entityMapping ); assertTyping( IncrementGenerator.class, generator ); }
getMetadata().getIdentifierGeneratorFactory(), dialect, defaultCatalog, getMetadata().getIdentifierGeneratorFactory(), dialect, defaultCatalog,
getMetadata().getIdentifierGeneratorFactory(), dialect, defaultCatalog, getMetadata().getIdentifierGeneratorFactory(), dialect, defaultCatalog,