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));
}
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);
}
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));
}
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));
}
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();
}
Aggregations