本文整理汇总了Java中org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationConfiguration.buildSessionFactory方法的具体用法?Java AnnotationConfiguration.buildSessionFactory怎么用?Java AnnotationConfiguration.buildSessionFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.cfg.AnnotationConfiguration
的用法示例。
在下文中一共展示了AnnotationConfiguration.buildSessionFactory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAnnotated
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
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.
}
示例2: HibernateHelper
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
/**
* 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();
}
}
示例3: setUp
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
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);
}
示例4: getSessionFactory
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
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();
}
}
示例5: init
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
public void init() {
ins = this;
logger.debug("Server init");
AnnotationConfiguration conf = (new AnnotationConfiguration())
.configure();
fct = conf.buildSessionFactory();
service = Executors.newCachedThreadPool();
scheduledService = Executors.newScheduledThreadPool(5);
}
示例6: buildSessionFactory
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
private static SessionFactory buildSessionFactory() {
try {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure("hibernate.cfg.xml");
return cfg.buildSessionFactory();
} catch (Throwable e) {
System.out.println("Criação inicial do objeto SessionFactory falhou. Erro: " + e);
throw new ExceptionInInitializerError(e);
}
}
示例7: getSession
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
public static Session getSession() {
AnnotationConfiguration conf = new AnnotationConfiguration();
conf.configure();
SessionFactory factory = conf.buildSessionFactory();
Session session = factory.openSession();
return session;
}
示例8: DAOFactory
import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
private DAOFactory() {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Topography.class);
cfg.addAnnotatedClass(TopographyCategory.class);
cfg.addAnnotatedClass(TopographyGroup.class);
cfg.addAnnotatedClass(Morphology.class);
cfg.addAnnotatedClass(MorphologyGroup.class);
cfg.addAnnotatedClass(RHC.class);
cfg.addAnnotatedClass(DCE.class);
cfg.addAnnotatedClass(SighReport.class);
cfg.addAnnotatedClass(Patient.class);
cfg.configure();
// TODO set fetch size according to Constants.BATCH_SIZE
if (Constants.RECREATE_DB) {
SchemaExport se = new SchemaExport(cfg);
se.create(true, true);
}
this.sessionFactory = cfg.buildSessionFactory();
for (int i = 0; i < CONNECTIONS; i++)
session[i] = sessionFactory.openSession();
for (int i = 0; i < CONNECTIONS; i++)
topographyDAO[i] = new TopographyDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
topographyCategoryDAO[i] = new TopographyCategoryDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
topographyGroupDAO[i] = new TopographyGroupDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
morphologyDAO[i] = new MorphologyDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
morphologyGroupDAO[i] = new MorphologyGroupDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
dceDAO[i] = new DceDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
sighDAO[i] = new SighDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
rhcDAO[i] = new RhcDAO(session[i]);
for (int i = 0; i < CONNECTIONS; i++)
patientDAO[i] = new PatientDAO(session[i]);
}