List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(String entityName, Object object);
From source file:com.gemstone.gemfire.modules.HibernateJUnitTest.java
License:Apache License
@Test public void testInsert() { Session session = getSessionFactory(null).openSession(); Region r = GemFireCacheImpl.getExisting().getRegion(Person.class.getCanonicalName()); int initSize = r.size(); session.beginTransaction();//from w w w. ja va 2 s. co m log.info("SWAP: Saving Person"); Person p = new Person(); p.setId(10L); p.setFirstname("foo"); p.setLastname("bar"); session.saveOrUpdate("Person", p); session.getTransaction().commit(); assertEquals(1, session.getStatistics().getEntityCount()); assertEquals(initSize + 1, r.size()); session.beginTransaction(); p.setAge(1); session.saveOrUpdate(p); session.getTransaction().commit(); assertEquals(1, session.getStatistics().getEntityCount()); }
From source file:com.jdon.persistence.hibernate.HibernateTemplate.java
License:Apache License
public void saveOrUpdate(final String entityName, final Object entity) throws Exception { doHibernate(new HibernateCallback() { public Object execute(Session session) throws HibernateException { session.saveOrUpdate(entityName, entity); return null; }/*from w ww . ja v a2s. c o m*/ }); }
From source file:com.nominanuda.hibernate.HibernateDataObjectStore.java
License:Apache License
public void put(String type, DataObject o, Session session, Transaction tx) throws Exception { //TODO//www . ja v a2 s .co m Map<String, ? super Object> entity = struct.toMapsAndSetLists((DataObject) o); session.saveOrUpdate(type, entity); }