List of usage examples for org.hibernate.jpa AvailableSettings LOADED_CLASSES
String LOADED_CLASSES
To view the source code for org.hibernate.jpa AvailableSettings LOADED_CLASSES.
Click Source Link
From source file:com.lg.hibernate.guide.test.BaseEntityManagerFunctionalTestCase.java
License:LGPL
protected Map getConfig() { Map<Object, Object> config = Environment.getProperties(); ArrayList<Class> classes = new ArrayList<Class>(); classes.addAll(Arrays.asList(getAnnotatedClasses())); config.put(AvailableSettings.LOADED_CLASSES, classes); for (Map.Entry<Class, String> entry : getCachedClasses().entrySet()) { config.put(AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(), entry.getValue()); }/*from ww w. j a v a 2s . c o m*/ for (Map.Entry<String, String> entry : getCachedCollections().entrySet()) { config.put(AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(), entry.getValue()); } if (getEjb3DD().length > 0) { ArrayList<String> dds = new ArrayList<String>(); dds.addAll(Arrays.asList(getEjb3DD())); config.put(AvailableSettings.XML_FILE_NAMES, dds); } addConfigOptions(config); return config; }
From source file:com.yahoo.elide.datastores.hibernate5.HibernateEntityManagerDataStoreSupplier.java
License:Apache License
@Override public DataStore get() { // Add additional checks to our static check mappings map. // NOTE: This is a bit hacky. We need to do a major overhaul on our test architecture TestCheckMappings.MAPPINGS.put("filterCheck", Filtered.FilterCheck.class); TestCheckMappings.MAPPINGS.put("filterCheck3", Filtered.FilterCheck3.class); Map<String, Object> options = new HashMap<>(); ArrayList<Class> bindClasses = new ArrayList<>(); try {// w w w. j av a 2 s . com bindClasses.addAll(ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class)); } catch (MappingException e) { throw new IllegalStateException(e); } options.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); options.put("javax.persistence.jdbc.url", JDBC_PREFIX + System.getProperty(MYSQL_PORT_PROPERTY, MYSQL_PORT) + JDBC_SUFFIX); options.put("javax.persistence.jdbc.user", ROOT); options.put("javax.persistence.jdbc.password", ROOT); options.put(AvailableSettings.LOADED_CLASSES, bindClasses); EntityManagerFactory emf = Persistence.createEntityManagerFactory("elide-tests", options); HibernateEntityManager em = (HibernateEntityManager) emf.createEntityManager(); // method to force class initialization MetadataSources metadataSources = new MetadataSources(new StandardServiceRegistryBuilder() .configure("hibernate.cfg.xml").applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread") .applySetting(Environment.URL, JDBC_PREFIX + System.getProperty(MYSQL_PORT_PROPERTY, MYSQL_PORT) + JDBC_SUFFIX) .applySetting(Environment.USER, ROOT).applySetting(Environment.PASS, ROOT).build()); try { ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class) .forEach(metadataSources::addAnnotatedClass); } catch (MappingException e) { throw new IllegalStateException(e); } MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata(); EnumSet<TargetType> type = EnumSet.of(TargetType.DATABASE); // create example tables from beans SchemaExport schemaExport = new SchemaExport(); schemaExport.drop(type, metadataImplementor); schemaExport.execute(type, SchemaExport.Action.CREATE, metadataImplementor); if (!schemaExport.getExceptions().isEmpty()) { throw new IllegalStateException(schemaExport.getExceptions().toString()); } return new AbstractHibernateStore.Builder(em).withScrollEnabled(true) .withScrollMode(ScrollMode.FORWARD_ONLY).build(); }
From source file:dk.dma.msinm.test.MsiNmUnitTest.java
License:Open Source License
/** * Should be called in sub-classes with the entity classes used in the test * @param entityClasses the entity classes *///from w w w. ja v a 2 s .com public static void prepareEntityManagerFactory(Class<?>... entityClasses) throws ClassNotFoundException { Class.forName("org.h2.Driver"); Map<Object, Object> props = new HashMap<>(); props.put(AvailableSettings.LOADED_CLASSES, Arrays.asList(entityClasses)); props.put("hibernate.cache.use_second_level_cache", "false"); props.put("hibernate.cache.use_query_cache", "false"); entityManagerFactory = Persistence.createEntityManagerFactory(TEST_UNIT_NAME, props); entityManager = entityManagerFactory.createEntityManager(); TestResources.entityManager = entityManager; entityManager.getTransaction().begin(); }
From source file:io.kloudwork.app.App.java
License:Open Source License
private EntityManager initDatabase() { Map<String, Object> props = new HashMap<>(); final Config config = Container.getInstance().getConfig(); String database = config.getProperties().getProperty("database.database"); String host = config.getProperties().getProperty("database.host"); String timeZone = config.getProperties().getProperty("database.timezone"); String jdbcUrl = "jdbc:mysql://" + host + "/" + database + "?serverTimezone=" + timeZone; List<Class<?>> entityClasses = new ArrayList<>(); this.getEntityClasses(entityClasses); props.put("hibernate.connection.url", jdbcUrl); props.put(AvailableSettings.LOADED_CLASSES, entityClasses); props.put("hibernate.connection.username", config.getProperties().getProperty("database.user")); props.put("hibernate.connection.password", config.getProperties().getProperty("database.password")); final EntityManagerFactory factory = Persistence.createEntityManagerFactory("mysql", props); return factory.createEntityManager(); }
From source file:org.jooby.hbm.Hbm.java
License:Apache License
private static Map<Object, Object> config(final Env env, final Config config, final List<Class<?>> classes) { Map<Object, Object> $ = new HashMap<>(); config.getConfig("hibernate").entrySet() .forEach(e -> $.put("hibernate." + e.getKey(), e.getValue().unwrapped())); if (classes.size() > 0) { $.put(AvailableSettings.LOADED_CLASSES, classes); }//from w w w . j a v a2 s . co m if (!config.hasPath("hibernate.hbm2ddl.auto")) { String hbm2ddl = env.name().equals("dev") ? "update" : "validate"; $.put("hibernate.hbm2ddl.auto", hbm2ddl); } return $; }