use of org.hibernate.boot.Metadata in project tutorials by eugenp.
the class HibernateSessionUtil method makeSessionFactory.
private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) {
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
metadataSources.addAnnotatedClass(User.class);
Metadata metadata = metadataSources.buildMetadata();
return metadata.getSessionFactoryBuilder().build();
}
use of org.hibernate.boot.Metadata in project giftcard-demo-series by AxonIQ.
the class PrimaryJpaConfig method main.
/**
**********************************************************************
* Simple utility to generate an initial version of the DDL
***********************************************************************
*/
public static void main(String[] args) {
Map<String, Object> settings = new HashMap<>();
settings.put("hibernate.dialect", PostgreSQL94Dialect.class);
settings.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class);
settings.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class);
StandardServiceRegistry standardServiceRegistry = new StandardServiceRegistryBuilder().applySettings(settings).build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
metadataSources.addAnnotatedClass(TokenEntry.class);
metadataSources.addAnnotatedClass(CardSummary.class);
Metadata metadata = metadataSources.buildMetadata();
SchemaExport schemaExport = new SchemaExport((MetadataImplementor) metadata);
schemaExport.setFormat(true);
schemaExport.setDelimiter(";");
schemaExport.create(Target.SCRIPT);
}
use of org.hibernate.boot.Metadata in project back2school by polimi-mt-acg.
the class DatabaseHandler method truncateDatabase.
public void truncateDatabase() {
Session session = getInstance().getNewSession();
session.beginTransaction();
LOGGER.info("Executing truncateDatabase");
Metadata metadata = new MetadataSources(registry).buildMetadata();
// shutoff the foreign key checks
session.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate();
// Iterate over namespaces
for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
if (namespace == null) {
LOGGER.warning("Found null namespace");
break;
}
for (Table table : namespace.getTables()) {
if (table == null) {
LOGGER.warning("Found null table");
break;
}
String tableName = table.getName();
if (!tableName.equals("hibernate_sequence")) {
String query = String.format("TRUNCATE TABLE `%s`", tableName);
LOGGER.info("Executing query: " + query);
session.createNativeQuery(query).executeUpdate();
}
}
}
// turn on again the foreign key checks
session.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate();
// reset hibernate auto increment reference indexes
session.createNativeQuery("UPDATE hibernate_sequence SET next_val = 1").executeUpdate();
session.getTransaction().commit();
session.close();
LOGGER.info("Database truncated");
}
use of org.hibernate.boot.Metadata in project ignite by apache.
the class HibernateL2CacheSelfTest method startHibernate.
/**
* Starts Hibernate.
*
* @param accessType Cache access type.
* @param igniteInstanceName Ignite instance name.
* @return Session factory.
*/
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = registryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue());
// Use the same cache for Entity and Entity2.
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
StandardServiceRegistry srvcRegistry = builder.build();
MetadataSources metadataSources = new MetadataSources(srvcRegistry);
for (Class entityClass : getAnnotatedClasses()) metadataSources.addAnnotatedClass(entityClass);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings()) collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName());
return metadata.buildSessionFactory();
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class CorrectnessTestCase method buildMetadata.
private Metadata buildMetadata(StandardServiceRegistry registry) {
MetadataSources metadataSources = new MetadataSources(registry);
for (Class entityClass : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass(entityClass);
}
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited()) {
((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
}
// Collections don't have integrated version, these piggyback on parent's owner version (for DB).
// However, this version number isn't extractable and is not passed to cache methods.
AccessType collectionAccessType = accessType == AccessType.NONSTRICT_READ_WRITE ? AccessType.READ_WRITE : accessType;
for (Collection collectionBinding : metadata.getCollectionBindings()) {
collectionBinding.setCacheConcurrencyStrategy(collectionAccessType.getExternalName());
}
return metadata;
}
Aggregations