List of usage examples for org.hibernate.internal StatelessSessionImpl insert
@Override
public Serializable insert(Object entity)
From source file:debop4k.data.orm.hibernate.stateless.StatelessExTest.java
License:Apache License
@Test @SuppressWarnings("unchecked") public void hibernateStatelessSessionDirectly() { StatelessEx.withTransaction(sf, new Function1<StatelessSessionImpl, Object>() { @Override//from ww w . j a va2 s .c om public Object invoke(StatelessSessionImpl stateless) { for (int i = 0; i < 10; i++) { Employee emp = new Employee(); emp.setEmpNo("empNo-" + i); emp.setName("empName-" + i); stateless.insert(emp); } return null; } }); List<Employee> emps = StatelessEx.withReadOnly(sf, new Function1<StatelessSessionImpl, List<Employee>>() { @Override public List<Employee> invoke(StatelessSessionImpl stateless) { Criteria criteria = stateless.createCriteria(Employee.class); return (List<Employee>) criteria.list(); } }); assertThat(emps).isNotNull(); assertThat(emps.size()).isGreaterThan(0); for (Employee emp : emps) { log.trace("emp={}", emp); } }
From source file:debop4k.data.orm.jpa.stateless.StatelessExWithJpaTest.java
License:Apache License
@Transactional @Test// w w w . j a v a 2 s . co m @SuppressWarnings("unchecked") public void hibernateStatelessSessionDirectly() { StatelessEx.withTransaction(em, new Function1<StatelessSessionImpl, Object>() { @Override public Object invoke(StatelessSessionImpl stateless) { for (int i = 0; i < 10; i++) { Employee emp = new Employee(); emp.setEmpNo("empNo-" + i); emp.setName("empName-" + i); stateless.insert(emp); } return null; } }); List<Employee> emps = StatelessEx.withReadOnly(em, new Function1<StatelessSessionImpl, List<Employee>>() { @Override public List<Employee> invoke(StatelessSessionImpl stateless) { Criteria criteria = stateless.createCriteria(Employee.class); return (List<Employee>) criteria.list(); } }); assertThat(emps).isNotNull(); assertThat(emps.size()).isGreaterThan(0); for (Employee emp : emps) { log.debug("emp={}", emp); } }