Refine search
@After public void cleanUpData() { Session s = openSession(); s.beginTransaction(); s.delete( s.get( Store.class, 1 ) ); s.delete( s.get( Product.class, "007" ) ); s.getTransaction().commit(); s.close(); }
/** * reads the newly created MainObject * and its Object2 if it exists * <p/> * one hibernate transaction */ private MainObject readMainObject() throws HibernateException { Long returnId = null; Session session = openSession(); Transaction tx = session.beginTransaction(); Serializable id = generatedId; MainObject mo = ( MainObject ) session.get( MainObject.class, id ); tx.commit(); session.close(); return mo; } }
@Override void check(boolean simplePropertyUpdated) { super.check( simplePropertyUpdated ); Session s = openSession(); Transaction tx = s.beginTransaction(); Node node1 = ( Node ) s.get( Node.class, Integer.valueOf( 1 ) ); Node node2 = ( Node ) s.get( Node.class, Integer.valueOf( 2 ) ); Node node3 = ( Node ) s.get( Node.class, Integer.valueOf( 3 ) ); assertEquals( 1, node1.getVersion() ); assertEquals( 1, node2.getVersion() ); assertEquals( 1, node3.getVersion() ); tx.commit(); s.close(); } }
@Test public void testCollectionCacheEvictionRemove() { People people = createPeople(); people = initCache( people.id ); Session session = openSession(); session.beginTransaction(); people = session.get( People.class, people.id ); Person person = people.people.remove( 0 ); session.delete( person ); session.getTransaction().commit(); session.close(); session = openSession(); people = session.get( People.class, people.id ); assertEquals( 1, people.people.size() ); session.close(); }
@Test public void testTemporalKeyMap() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Atmosphere atm = new Atmosphere(); atm.colorPerDate.put( new Date(1234567000), "red" ); s.persist( atm ); s.flush(); s.clear(); atm = (Atmosphere) s.get( Atmosphere.class, atm.id ); assertEquals( 1, atm.colorPerDate.size() ); final Date date = atm.colorPerDate.keySet().iterator().next(); final long diff = new Date( 1234567000 ).getTime() - date.getTime(); assertTrue( "24h diff max", diff >= 0 && diff < 24*60*60*1000 ); tx.rollback(); s.close(); }
public void testWorksWithGenericCollectionOfElements() { Session session = openSession(); session.beginTransaction(); Classes.Edition<String> edition = new Classes.Edition<String>(); edition.name = "Second"; Classes.PopularBook b = new Classes.PopularBook(); b.editions.add( edition ); session.persist( b ); session.getTransaction().commit(); session.close(); session = openSession(); session.beginTransaction(); Classes.PopularBook retrieved = (Classes.PopularBook) session.get( Classes.PopularBook.class, b.id ); assertEquals( "Second", retrieved.editions.iterator().next().name ); session.delete( retrieved ); session.getTransaction().commit(); session.close(); }
private void compareSavedZonedDateTimeWith(ZonedDateTime startdate) { final Session s = openSession(); try { final ZonedDateTimeEvent zonedDateTimeEvent = s.get( ZonedDateTimeEvent.class, 1L ); assertThat( ZonedDateTimeType.INSTANCE.getComparator().compare( zonedDateTimeEvent.startDate, startdate ), is( 0 ) ); } finally { s.close(); } }
@Test public void testSequenceGenerator() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Shoe b = new Shoe(); s.persist( b ); tx.commit(); s.close(); assertNotNull( b.getId() ); s = openSession(); tx = s.beginTransaction(); s.delete( s.get( Shoe.class, b.getId() ) ); tx.commit(); s.close(); }
@org.junit.Test public void basicTest() { Session s = openSession(); s.beginTransaction(); User user = new User( 2 ); s.save( user ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); assertNotNull( s.get( User.class, 2 ) ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.createQuery( "delete User" ).executeUpdate(); s.getTransaction().commit(); s.close(); } }
@Test public void testClassLevelGenerator() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Store b = new Store(); s.persist( b ); tx.commit(); s.close(); assertNotNull( b.getId() ); s = openSession(); tx = s.beginTransaction(); s.delete( s.get( Store.class, b.getId() ) ); tx.commit(); s.close(); }
@Test public void testSaving() { byte[] testData = "test data".getBytes(); Session session = openSession(); session.beginTransaction(); MaterializedBlobEntity entity = new MaterializedBlobEntity( "test", testData ); session.save( entity ); session.getTransaction().commit(); session.close(); session = openSession(); session.beginTransaction(); entity = ( MaterializedBlobEntity ) session.get( MaterializedBlobEntity.class, entity.getId() ); assertTrue( Arrays.equals( testData, entity.getTheBytes() ) ); session.delete( entity ); session.getTransaction().commit(); session.close(); } }
@Test @TestForIssue( jiraKey = "HHH-10166" ) public void testGenerationPastBound() { Session session = openSession(); session.getTransaction().begin(); for (int i = 0; i < 100; i++) { TheEntity entity = new TheEntity( Integer.toString( i ) ); session.save( entity ); } session.getTransaction().commit(); session.close(); session = openSession(); session.getTransaction().begin(); TheEntity number100 = session.get( TheEntity.class, 100 ); assertThat( number100, notNullValue() ); session.createQuery( "delete TheEntity" ).executeUpdate(); session.getTransaction().commit(); session.close(); }