Search in sources :

Example 76 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class GeneratedValueTests method baseline.

@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));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 77 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class GeneratedValueTests method testExplicitIncrementGenerator.

@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);
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 78 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class GeneratedValueTests method testImplicitSequenceGenerator.

@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));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 79 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class GeneratedValueTests method testExplicitSequenceGeneratorImplicitName.

@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));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 80 with Metadata

use of org.hibernate.boot.Metadata in project tutorials by eugenp.

the class HibernateUtil method makeSessionFactory.

private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) {
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    metadataSources.addPackage("com.baeldung.hibernate.pojo");
    metadataSources.addAnnotatedClass(Employee.class);
    metadataSources.addAnnotatedClass(Phone.class);
    metadataSources.addAnnotatedClass(EntityDescription.class);
    metadataSources.addAnnotatedClass(TemporalValues.class);
    metadataSources.addAnnotatedClass(User.class);
    metadataSources.addAnnotatedClass(Student.class);
    metadataSources.addAnnotatedClass(Course.class);
    metadataSources.addAnnotatedClass(Product.class);
    metadataSources.addAnnotatedClass(OrderEntryPK.class);
    metadataSources.addAnnotatedClass(OrderEntry.class);
    metadataSources.addAnnotatedClass(OrderEntryIdClass.class);
    metadataSources.addAnnotatedClass(UserProfile.class);
    metadataSources.addAnnotatedClass(Book.class);
    metadataSources.addAnnotatedClass(MyEmployee.class);
    metadataSources.addAnnotatedClass(MyProduct.class);
    metadataSources.addAnnotatedClass(Pen.class);
    metadataSources.addAnnotatedClass(Person.class);
    metadataSources.addAnnotatedClass(Animal.class);
    metadataSources.addAnnotatedClass(Pet.class);
    metadataSources.addAnnotatedClass(Vehicle.class);
    metadataSources.addAnnotatedClass(Car.class);
    metadataSources.addAnnotatedClass(Bag.class);
    metadataSources.addAnnotatedClass(PointEntity.class);
    metadataSources.addAnnotatedClass(PolygonEntity.class);
    metadataSources.addAnnotatedClass(com.baeldung.hibernate.pojo.Person.class);
    Metadata metadata = metadataSources.buildMetadata();
    return metadata.getSessionFactoryBuilder().build();
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata)

Aggregations

Metadata (org.hibernate.boot.Metadata)148 MetadataSources (org.hibernate.boot.MetadataSources)124 Test (org.junit.Test)103 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)73 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)56 PersistentClass (org.hibernate.mapping.PersistentClass)46 TestForIssue (org.hibernate.testing.TestForIssue)31 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)18 Session (org.hibernate.Session)14 HashMap (java.util.HashMap)13 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)13 Property (org.hibernate.mapping.Property)12 RootClass (org.hibernate.mapping.RootClass)12 Map (java.util.Map)11 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 SessionFactory (org.hibernate.SessionFactory)10 Collection (org.hibernate.mapping.Collection)10 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)10 ServiceRegistry (org.hibernate.service.ServiceRegistry)8 Before (org.junit.Before)8