public static void ReloadConfig() { try { AnnotationConfiguration config = new AnnotationConfiguration(); Conexion conn = configDB.config(); /* <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/zille2</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">infomati</property>*/ config.setProperty("hibernate.connection.url", "jdbc:mysql://" + conn.getHost() + ":3306/" + conn.getDbname()); config.setProperty("hibernate.connection.username", conn.getDbuser()); config.setProperty("hibernate.connection.password", conn.getDbpass()); System.out.println("Reiniciando configuración hibernate"); sessionFactory = config.configure().buildSessionFactory(); } catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
/** * Reads metadata from annotated classes and packages into the * AnnotationConfiguration instance. */ @Override protected void postProcessMappings(Configuration config) throws HibernateException { AnnotationConfiguration annConfig = (AnnotationConfiguration) config; if (this.annotatedClasses != null) { for (Class<?> annotatedClass : this.annotatedClasses) { annConfig.addAnnotatedClass(annotatedClass); } } if (this.annotatedPackages != null) { for (String annotatedPackage : this.annotatedPackages) { annConfig.addPackage(annotatedPackage); } } scanPackages(annConfig); }
private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml return new AnnotationConfiguration().configure() .addAnnotatedClass(AccountModel.class) .addAnnotatedClass(RESTServiceModel.class) .addAnnotatedClass(ResourceModel.class) .addAnnotatedClass(RESTMethodModel.class) .addAnnotatedClass(RESTParameterModel.class) .addAnnotatedClass(InputMessageModel.class) .addAnnotatedClass(InputParameterModel.class) .addAnnotatedClass(OutputMessageModel.class) .addAnnotatedClass(OutputParameterModel.class) .addAnnotatedClass(SOAPOperationModel.class) .addAnnotatedClass(SOAPServiceModel.class) .buildSessionFactory();//TODO add the rest models here } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
public static Session getSession() { if (sessionFactory == null) { synchronized (HibernateManager.class) { if (sessionFactory == null) { try { log.info("Creating new Content SessionFactory"); sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } catch (Throwable ex) { log.error("Initial Content SessionFactory creation failed.", ex); throw new ExceptionInInitializerError(ex); } } } } return sessionFactory.openSession(); }
public void testAnnotated(){ SessionFactory sf=null; AnnotationConfiguration configuration= null; String hibernateCfgFileName = "instanceleveltest_annotations.hibernate.cfg.xml"; configuration = new AnnotationConfiguration().configure(hibernateCfgFileName); sf = configuration.buildSessionFactory(); Session session = null; session = sf.openSession(); Criteria criteria = session.createCriteria(Card.class); List l = criteria.list(); int size = l.size(); System.out.println("============= Annotated SYSTEM =================="); System.out.println("Total no of Cards on which user has access= "+l.size()); System.out.println("------------------------------------------------------"); session.close(); sf.close(); assertEquals("Incorrect number of cards retrieved",size, 53); // Expecting all cards in the deck including the joker. }
/** * @param args */ public static void main(String[] args) { // Configuration config = new AnnotationConfiguration().configure(); AnnotationConfiguration config = new AnnotationConfiguration().configure(); config.addAnnotatedClass(TUser.class) .addAnnotatedClass(TGameDetailRecord.class) .addAnnotatedClass(TMatch.class) .addAnnotatedClass(TMatchType.class) .addAnnotatedClass(TResult.class); /* config.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); new SchemaExport(cfg, connection);*/ SchemaExport se = new SchemaExport(config); se.create(true, true); }
/** * Constructor to build the hibernate helper. * @param namingStrategy the name strategy, if one is needed, null otherwise. * @param interceptor the interceptor, if one is needed, null otherwise. */ public HibernateHelper(NamingStrategy namingStrategy, Interceptor interceptor) { try { configuration = new AnnotationConfiguration(); initializeConfig(namingStrategy, interceptor); configuration = configuration.configure(); // We call buildSessionFactory twice, because it appears that the annotated classes are // not 'activated' in the config until we build. The filters required the classes to // be present, so we throw away the first factory and use the second. If this is // removed, you'll likely see a NoClassDefFoundError in the unit tests configuration.buildSessionFactory(); sessionFactory = configuration.buildSessionFactory(); } catch (HibernateException e) { // LOG.error(e.getMessage(), e); // throw new ExceptionInInitializerError(e); LOG.warn("Failed to initialize HibernateHelper using hibernate.cfg.xml. " + "This is expected behavior during unit testing." , e); e.printStackTrace(); } }
public static void setUp() { AnnotationConfiguration config = new AnnotationConfiguration(); config.setProperty("hibernate.current_session_context_class", "managed"); config.setProperty("hibernate.c3p0.max_size", "20").setProperty( "hibernate.c3p0.timeout", "3000").setProperty( "hibernate.c3p0.idle_test_period", "300").setProperty("hibernate.hbm2ddl.auto", "update"); ConstellioAnnotationUtils.addAnnotatedClasses(config); sessionFactory = config.buildSessionFactory(); Application.set(new DataDummyWebApplication()); org.hibernate.classic.Session hibernateSession = sessionFactory.openSession(); hibernateSession.beginTransaction(); ManagedSessionContext.bind(hibernateSession); }
private void testarConexao1(){ new Thread(){ @Override public void run(){ Session session= null; try{ progress.setString("Testando Conexão com o Banco de Dados"); session = new AnnotationConfiguration().configure().setProperty("hibernate.connection.username", "root").setProperty("hibernate.connection.password", "123").buildSessionFactory().openSession(); }catch(HibernateException e){ JOptionPane.showMessageDialog(null, "Erro de conexão ao banco de dados: "+e.getMessage()); System.exit(1); }finally{ if(session != null){ session.close(); } } progress.setString("Conexão bem sucedida..."); } }.start(); }
@BeforeClass public final void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .addAccessor(AbstractWithDF.class) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); injector.getInstance(PersistenceService.class).start(); }
@BeforeMethod public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .addAccessor(AbstractDF.class) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntityTxnal.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); injector.getInstance(PersistenceService.class).start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .addAccessor(HibernateTestAccessor.class) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); injector.getInstance(PersistenceService.class).start(); }
@BeforeMethod public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .addAccessor(HibernateTestAccessorForDFs.class) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntityTxnal.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); injector.getInstance(PersistenceService.class).start(); }
@BeforeMethod public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(Matchers.annotatedWith(Transactional.class), Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } } ); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST) .forAll(Matchers.subclassesOf(TransactionalObject.class), Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spr-managed-persistence.properties"))); } }); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spr-managed-persistence.properties"))); } }); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } } ); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeMethod public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } } ); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateTestEntity.class) .addAnnotatedClass(HibernateParentTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
@BeforeClass public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(Matchers.any()) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(ReadOnlyTransactionalObject.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } }); //startup persistence injector.getInstance(PersistenceService.class).start(); }
@BeforeMethod public void pre() { injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.TRANSACTION) .forAll(annotatedWith(Transactional.class), any()) .forAll(not(annotatedWith(Transactional.class)), annotatedWith(Transactional.class)) .buildModule(), new AbstractModule() { protected void configure() { bind(Configuration.class).toInstance(new AnnotationConfiguration() .addAnnotatedClass(HibernateAdvancedTxTestEntity.class) .setProperties(Initializer.loadProperties("spt-persistence.properties"))); } } ); //startup persistence injector.getInstance(PersistenceService.class) .start(); }
private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml return new AnnotationConfiguration().configure() .buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
@BeforeClass public static void runBeforeClass() throws Exception { // ApplicationContext context = // new ClassPathXmlApplicationContext("beans-hibernate.xml"); // dao = (MemberDao) context.getBean("memberDao"); Configuration configuration = new AnnotationConfiguration().configure(); sessionFactory = configuration.buildSessionFactory(); }
/** * <p>Constructor for HibernateDatabase.</p> * * @param properties a {@link java.util.Properties} object. * @throws org.hibernate.HibernateException if any. */ public HibernateDatabase(Properties properties) throws HibernateException { cfg = new AnnotationConfiguration(); cfg.setProperties(properties); setAnnotadedClasses(); loadConfig(); }
/** * <p>Constructor for HibernateDatabase.</p> * * @param properties a {@link java.util.Properties} object. * @throws org.hibernate.HibernateException if any. */ public HibernateDatabase(Properties properties) throws HibernateException { cfg = new AnnotationConfiguration(); cfg.setProperties(properties); setAnnotadedClasses(); }
public static synchronized SessionFactory getSessionFactory() throws HibernateException { if (sessionFactory == null) { sessionFactory = new AnnotationConfiguration() // see http://java.dzone.com/articles/hibernate-3-annotations?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+javalobby%2Ffrontpage+%28Javalobby+%2F+Java+Zone%29 .addPackage("context.arch.logging.hibernate") .addAnnotatedClass(ComponentSubscription.class) .addAnnotatedClass(ComponentUpdate.class) .addAnnotatedClass(CUAttribute.class) .addAnnotatedClass(CUDestination.class) .addAnnotatedClass(WidgetRegistration.class) .addAnnotatedClass(WRAttribute.class) .addAnnotatedClass(WRCallback.class) .addAnnotatedClass(WRService.class) .addAnnotatedClass(WRServiceFunction.class) .addAnnotatedClass(EnactorRegistration.class) .addAnnotatedClass(ERParameter.class) .addAnnotatedClass(ERReference.class) .addAnnotatedClass(ComponentEvaluated.class) .addAnnotatedClass(ComponentAdded.class) .addAnnotatedClass(CAParamAttribute.class) .addAnnotatedClass(ParameterValueChanged.class) .addAnnotatedClass(PVCParamAttribute.class) .addAnnotatedClass(ServiceExecution.class) .addAnnotatedClass(SEInputAttribute.class) .buildSessionFactory(); } return sessionFactory; }
@Before public void setUp() throws Exception { Configuration config = new AnnotationConfiguration(); config.configure("/hibernate-tests.cfg.xml"); sessionFactory = config.buildSessionFactory(); session = sessionFactory.openSession(); beginTransaction(); }
public SessionFactory getSessionFactory() throws org.hibernate.HibernateException { if (useAnnotations) { AnnotationConfiguration conf = new org.hibernate.cfg.AnnotationConfiguration().configure(); conf.setProperty(Environment.CONNECTION_PROVIDER, "com.jaspersoft.ireport.designer.connection.HibernateConnectionProvider"); return conf.buildSessionFactory(); } else { return new Configuration().configure().buildSessionFactory(); } }
@Override public void setConfigurationClass(Class<?> configurationClass) { if (configurationClass == null || !AnnotationConfiguration.class.isAssignableFrom(configurationClass)) { throw new IllegalArgumentException( "AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses"); } super.setConfigurationClass(configurationClass); }
public static SessionFactory buildSessionFactoryFromAnnotations() { try { sessionFactory = new AnnotationConfiguration() .setNamingStrategy(ImprovedNamingStrategy.INSTANCE) .configure("/hib.cfg.xml") .buildSessionFactory(); return sessionFactory; } catch (Throwable ex) { throw new ExceptionInInitializerError(ex); } }
public SqlTableCreator( String packageName ) throws Exception { cfg = new AnnotationConfiguration(); cfg.setProperty( "hibernate.hbm2ddl.auto", "create" ); for ( Class< Object > clazz : getClasses( packageName ) ) { cfg.addAnnotatedClass( clazz ); } }
public static void main(String[] args) { System.out.println("Inicio Export BD"); Configuration cfg = new AnnotationConfiguration().configure(); SchemaExport schemaExport = new SchemaExport(cfg); schemaExport.create(true,true); }
public void init() { ins = this; logger.debug("Server init"); AnnotationConfiguration conf = (new AnnotationConfiguration()) .configure(); fct = conf.buildSessionFactory(); service = Executors.newCachedThreadPool(); scheduledService = Executors.newScheduledThreadPool(5); }
public static void main(String args[]) { Configuration cfg = new AnnotationConfiguration(); cfg.configure("hibernate.cfg.xml"); SchemaExport se = new SchemaExport(cfg); se.create(true, true); }
public static void geraTabelas() { Configuration cfg = new AnnotationConfiguration(); cfg.configure("br/com/hslife/imobiliaria/db/hibernate.cfg.xml"); SchemaExport se = new SchemaExport(cfg); se.create(true, true); }
private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml return new AnnotationConfiguration() .configure() .buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }