javax.persistence.Persistence.createEntityManagerFactory()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中javax.persistence.Persistence.createEntityManagerFactory()方法的一些代码示例,展示了Persistence.createEntityManagerFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Persistence.createEntityManagerFactory()方法的具体详情如下:
包路径:javax.persistence.Persistence
类名称:Persistence
方法名:createEntityManagerFactory

Persistence.createEntityManagerFactory介绍

[英]Create and return an EntityManagerFactory for the named persistence unit.
[中]为命名的持久性单元创建并返回EntityManagerFactory。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void test_bootstrap_bootstrap_jpa_compliant_EntityManagerFactory_example() {
  try {
    //tag::bootstrap-jpa-compliant-EntityManagerFactory-example[]
    // Create an EMF for our CRM persistence-unit.
    EntityManagerFactory emf = Persistence.createEntityManagerFactory( "CRM" );
    //end::bootstrap-jpa-compliant-EntityManagerFactory-example[]
  } catch (Exception ignore) {}
}

代码示例来源:origin: kiegroup/drools

/**
 * This method does all of the setup for the test and returns a HashMap
 * containing the persistence objects that the test might need.
 *
 * @param persistenceUnitName
 *            The name of the persistence unit used by the test.
 * @return Map with persistence objects, such as the EntityManagerFactory and DataSource
 */
public static Map<String, Object> setupWithPoolingDataSource(final String persistenceUnitName, String dataSourceName, final boolean testMarshalling) {
  // Setup the datasource
  PoolingDataSourceWrapper ds1 = setupPoolingDataSource(getDatasourceProperties(), dataSourceName);
  Map<String, Object> context = new HashMap<String, Object>();
  context.put(DATASOURCE, ds1);
  EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);
  context.put(ENTITY_MANAGER_FACTORY, emf);
  return context;
}

代码示例来源:origin: kiegroup/jbpm

@Before
public void beforeThis() { 
  emf = Persistence.createEntityManagerFactory("org.jbpm.logging.jta");
  logService = new JPAAuditLogService(emf);
}

代码示例来源:origin: Impetus/Kundera

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception
{
  propertyMap.put("index.home.dir", "./lucene");
  emf = Persistence.createEntityManagerFactory("redisLucene_pu", propertyMap);
  em = emf.createEntityManager();
}

代码示例来源:origin: Impetus/Kundera

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception
{
  CassandraCli.cassandraSetUp();
  Map propertyMap = new HashMap();
  propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
  emf = Persistence.createEntityManagerFactory(persistenceUnit, propertyMap);
}

代码示例来源:origin: Impetus/Kundera

/**
 * On named query batch test.
 */
@Test
public void onNamedQueryBatchTest()
{
  Map propertyMap = new HashMap();
  propertyMap.put("kundera.batch.size", "5");
  emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, propertyMap);
  insertUpdateBatch();
  deleteBatch();
}

代码示例来源:origin: Impetus/Kundera

/**
 * Sets the up before class.
 */
@BeforeClass
public static void setUpBeforeClass()
{
  propertyMap.put("index.home.dir", "lucene");
  emf = Persistence.createEntityManagerFactory(HBASE_PU, propertyMap);
}

代码示例来源:origin: Impetus/Kundera

@Before
public void setUp() throws Exception
{
  emf = Persistence.createEntityManagerFactory("hbaseTest");
  em = emf.createEntityManager();
}

代码示例来源:origin: kiegroup/jbpm

@SuppressWarnings("unchecked")
@Test
public void testPerRequestManagerDestorySession() {
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
  RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
      .newDefaultBuilder()
      .get();
  EntityManager em = emf.createEntityManager();
  List<SessionInfo> sessions = em.createQuery("from SessionInfo").getResultList();
  assertEquals(0, sessions.size());

代码示例来源:origin: kiegroup/jbpm

@BeforeClass
public static void configure() {
  pds = setupPoolingDataSource();
  emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" );
  hackTheDatabaseMetadataLoggerBecauseTheresALogbackXmlInTheClasspath();
}

代码示例来源:origin: Impetus/Kundera

/**
 * Sets the up before class.
 * 
 * @throws Exception
 *             the exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
  emf = Persistence.createEntityManagerFactory(_PU);
  em = emf.createEntityManager();
}

代码示例来源:origin: hibernate/hibernate-orm

public static void main(String[] args) {
    Map<String, String> configurationOverrides = new HashMap<String, String>();
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("ConsolePU", configurationOverrides);
    EntityManager entityManager = emf.createEntityManager();

    TestConsole console = new TestConsole(entityManager);

    System.out.println("");
    System.out.println("Welcome to EntityVersions demo!");
//      If you would like to use HSQLDB, uncomment relevant entries in
//      hibernate-envers/src/demo/resources/META-INF/persistence.xml descriptor and add required JAR libraries.
//        String userDbFile = System.getProperty("java.io.tmpdir") + File.separator + "_versions_demo.db";
//        System.out.println("HSQLDB database file location: " + userDbFile);

    console.populateTestData();
    console.start();

    entityManager.close();
    emf.close();
  }
}

代码示例来源:origin: Impetus/Kundera

@Before
public void setUp() throws Exception
{
  propertyMap.put("index.home.dir", "lucene");
  emf = Persistence.createEntityManagerFactory(PU, propertyMap);
  em = emf.createEntityManager();
}

代码示例来源:origin: Impetus/Kundera

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception
{
  CassandraCli.cassandraSetUp();
  Map<String, Object> puProperties = new HashMap<String, Object>();
  puProperties.put("kundera.ddl.auto.prepare", "create-drop");
  
  emf = Persistence.createEntityManagerFactory(_PU, puProperties);
}

代码示例来源:origin: Impetus/Kundera

@Test
public void testCreate()
{
  Map<String, Object> props = new HashMap<String, Object>();
  props.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE, "create");
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("metaDataTest", props);
  Assert.assertTrue(CoreSchemaManager.validateAction("create"));
  emf.close();
  Assert.assertTrue(CoreSchemaManager.validateAction("create"));
  Assert.assertFalse(CoreSchemaManager.validateAction("drop"));
}

代码示例来源:origin: Impetus/Kundera

@BeforeClass
public static void setUpBeforeClass() throws Exception
{
  CassandraCli.cassandraSetUp();
  propertyMap = new HashMap();
  propertyMap.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE, "create");
  propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
  emf = Persistence.createEntityManagerFactory(PU, propertyMap);
}
/**

代码示例来源:origin: kiegroup/jbpm

@Test
  public void testRuntimeEnvironmentUserDataServiceProviderUserInfo() {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
         .newDefaultBuilder()
         .entityManagerFactory(emf)
         .get();

    LocalTaskServiceFactory factory = new LocalTaskServiceFactory(environment);
    InternalTaskService service = (InternalTaskService) factory.newTaskService();
    // the instance provided should be the one setup at custom and not the default one
    Assert.assertTrue(service.getUserInfo() instanceof CustomUserInfoImpl);
  }
}

代码示例来源:origin: kiegroup/jbpm

@Before
public void beforeThis() { 
  emf = Persistence.createEntityManagerFactory("org.jbpm.logging.local");
  logService = new JPAAuditLogService(emf, PersistenceStrategyType.STANDALONE_LOCAL);
}

代码示例来源:origin: Impetus/Kundera

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception
{
  emf = Persistence.createEntityManagerFactory("mongoTest");
  em = emf.createEntityManager();
}

代码示例来源:origin: kiegroup/jbpm

@SuppressWarnings("unchecked")
@Test
public void testPerProcessInstanceManagerDestorySession() {
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
  RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
      .newDefaultBuilder()
      .get();
  EntityManager em = emf.createEntityManager();
  List<SessionInfo> sessions = em.createQuery("from SessionInfo").getResultList();
  assertEquals(0, sessions.size());

相关文章