本文整理汇总了Java中javax.persistence.EntityManager.flush方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.flush方法的具体用法?Java EntityManager.flush怎么用?Java EntityManager.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Vote createEntity(EntityManager em) {
Vote vote = new Vote()
.userKey(DEFAULT_USER_KEY)
.value(DEFAULT_VALUE)
.message(DEFAULT_MESSAGE)
.entryDate(DEFAULT_ENTRY_DATE);
// Add required entity
XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
em.persist(xmEntity);
em.flush();
vote.setXmEntity(xmEntity);
Rating rating = RatingResourceIntTest.createEntity(em);
em.persist(rating);
em.flush();
vote.setRating(rating);
return vote;
}
示例2: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Attachment createEntity(EntityManager em) {
Attachment attachment = new Attachment()
.typeKey(DEFAULT_TYPE_KEY)
.name(DEFAULT_NAME)
.contentUrl(DEFAULT_CONTENT_URL)
.description(DEFAULT_DESCRIPTION)
.startDate(DEFAULT_START_DATE)
.endDate(DEFAULT_END_DATE)
.valueContentType(DEFAULT_VALUE_CONTENT_TYPE)
.valueContentSize(DEFAULT_VALUE_CONTENT_SIZE);
// Add required entity
XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
em.persist(xmEntity);
em.flush();
attachment.setXmEntity(xmEntity);
return attachment;
}
示例3: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Location createEntity(EntityManager em) {
Location location = new Location()
.typeKey(DEFAULT_TYPE_KEY)
.countryKey(DEFAULT_COUNTRY_KEY)
.longitude(DEFAULT_LONGITUDE)
.latitude(DEFAULT_LATITUDE)
.name(DEFAULT_NAME)
.addressLine1(DEFAULT_ADDRESS_LINE_1)
.addressLine2(DEFAULT_ADDRESS_LINE_2)
.city(DEFAULT_CITY)
.region(DEFAULT_REGION)
.zip(DEFAULT_ZIP);
// Add required entity
XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
em.persist(xmEntity);
em.flush();
location.setXmEntity(xmEntity);
return location;
}
示例4: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Link createEntity(EntityManager em) {
Link link = new Link()
.typeKey(DEFAULT_TYPE_KEY)
.name(DEFAULT_NAME)
.description(DEFAULT_DESCRIPTION)
.startDate(DEFAULT_START_DATE)
.endDate(DEFAULT_END_DATE);
// Add required entity
XmEntity target = XmEntityResourceIntTest.createEntity(em);
em.persist(target);
em.flush();
link.setTarget(target);
// Add required entity
XmEntity source = XmEntityResourceIntTest.createEntity(em);
em.persist(source);
em.flush();
link.setSource(source);
return link;
}
示例5: removeAll
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Removes all entities from database.
*/
public void removeAll() {
EntityManager em = HibernateUtil.getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
for (T t : findAll()) {
em.remove(em.merge(t));
}
em.flush();
em.clear();
em.getTransaction().commit();
em.close();
}
示例6: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Profile createEntity(EntityManager em) {
Profile profile = new Profile()
.userKey(DEFAULT_USER_KEY);
// Add required entity
Dashboard dashboard = DashboardResourceIntTest.createEntity(em);
em.persist(dashboard);
em.flush();
profile.setDashboards(new HashSet<>(Collections.singletonList(dashboard)));
return profile;
}
示例7: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static DefaultProfile createEntity(EntityManager em) {
DefaultProfile defaultProfile = new DefaultProfile()
.roleKey(DEFAULT_ROLE_KEY);
// Add required entity
Dashboard dashboard = DashboardResourceIntTest.createEntity(em);
em.persist(dashboard);
em.flush();
defaultProfile.setDashboard(dashboard);
return defaultProfile;
}
示例8: testOriginalExceptionThrown
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Test(expected=PersistenceException.class)
public void testOriginalExceptionThrown() {
EmSupplier emSupplier = mock(EmSupplier.class);
EntityManager em = mock(EntityManager.class);
when(emSupplier.get()).thenReturn(em);
doThrow(new PersistenceException("Message")).when(em).flush();
EntityManager emProxy = EMFTracker.createProxy(emSupplier);
emProxy.flush();
}
示例9: addCar
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void addCar(Car car) {
EntityManager em = emf.createEntityManager();
em.persist(car);
em.flush();
em.close();
}
示例10: remove
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Removes an existing entity from database.
*
* @param entity Entity to remove.
*/
public void remove(T entity) {
EntityManager em = HibernateUtil.getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
em.remove(em.merge(entity));
em.flush();
em.clear();
em.getTransaction().commit();
em.close();
}
示例11: clear
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static void clear(final EntityManager em, JpaQueryFactory factory) {
factory.initalize(new JpaQueryFactoryContext() {
@Override
public EntityManager getEntityManager() {
return em;
}
@Override
public MetaPartition getMetaPartition() {
JpaMetaProvider jpaMetaProvider = new JpaMetaProvider(em.getEntityManagerFactory());
MetaLookup metaLookup = new MetaLookup();
metaLookup.addProvider(jpaMetaProvider);
metaLookup.initialize();
return jpaMetaProvider.getPartition();
}
});
clear(em, factory.query(OneToOneTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(ManyToManyTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(ManyToManyOppositeEntity.class).buildExecutor().getResultList());
clear(em, factory.query(TestSubclassWithSuperclassPk.class).buildExecutor().getResultList());
clear(em, factory.query(RelatedEntity.class).buildExecutor().getResultList());
clear(em, factory.query(TestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(OtherRelatedEntity.class).buildExecutor().getResultList());
clear(em, factory.query(CountryTranslationEntity.class).buildExecutor().getResultList());
clear(em, factory.query(CountryEntity.class).buildExecutor().getResultList());
clear(em, factory.query(LangEntity.class).buildExecutor().getResultList());
clear(em, factory.query(BasicAttributesTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(RenamedTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(UuidTestEntity.class).buildExecutor().getResultList());
em.flush();
em.clear();
}
示例12: persist
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void persist(Object obj){
EntityManager em=this.getEntityManager();
try{
em.persist(obj);
}finally{
em.flush();
em.close();
}
}
示例13: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Rating createEntity(EntityManager em) {
Rating rating = new Rating()
.typeKey(DEFAULT_TYPE_KEY)
.value(DEFAULT_VALUE)
.startDate(DEFAULT_START_DATE)
.endDate(DEFAULT_END_DATE);
// Add required entity
XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
em.persist(xmEntity);
em.flush();
rating.setXmEntity(xmEntity);
return rating;
}
示例14: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Profile createEntity(EntityManager em, XmEntity xmEntity) {
Profile profile = new Profile()
.userKey(DEFAULT_USER_KEY);
// Add required entity
em.persist(xmEntity);
em.flush();
profile.setXmentity(xmEntity);
return profile;
}
示例15: createEntity
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Calendar createEntity(EntityManager em) {
Calendar calendar = new Calendar()
.typeKey(DEFAULT_TYPE_KEY)
.name(DEFAULT_NAME)
.description(DEFAULT_DESCRIPTION)
.startDate(DEFAULT_START_DATE)
.endDate(DEFAULT_END_DATE);
// Add required entity
XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
em.persist(xmEntity);
em.flush();
calendar.setXmEntity(xmEntity);
return calendar;
}