@Test public void testPackageQueries() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Plane p = new Plane(); s.persist( p ); Query q = s.getNamedQuery( "plane.getAll" ); assertEquals( 1, q.list().size() ); s.delete( q.list().get( 0 ) ); tx.commit(); s.close(); }
@Test(expected = TransactionRequiredException.class) public void testInsertOutsideActiveTransaction() { Session session = openSession(); // Illegal insertion of entity outside of active transaction. StrTestEntity entity = new StrTestEntity( "data" ); session.persist( entity ); session.flush(); 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(); }
@Before public void prepareTestData() { Session s = openSession(); s.getTransaction().begin(); AddressType homeType = new AddressType( 1, "home" ); s.persist( homeType ); Address address = new Address( 1, "Main St.", "Somewhere, USA" ); s.persist( address ); Contact contact = new Contact( 1, "John" ); contact.addresses.put( homeType, address ); s.persist( contact ); s.getTransaction().commit(); s.close(); }
@Test(expected = PersistenceException.class) @TestForIssue(jiraKey = "HHH-12132") public void testBooleanTypeLegacyBehavior() throws Exception { rebuildSessionFactory( configuration -> { configuration.setProperty( "hibernate.dialect.hana.use_legacy_boolean_type", Boolean.TRUE.toString() ); } ); Session s = openSession(); s.beginTransaction(); BooleanEntity entity = new BooleanEntity(); entity.key = Integer.valueOf( 2 ); entity.bool = Boolean.FALSE; s.persist( entity ); s.flush(); s.getTransaction().commit(); s.clear(); Query<BooleanEntity> query = s.createQuery( "select b from " + ENTITY_NAME + " b where bool = true", BooleanEntity.class ); query.getSingleResult(); }
@Test @TestForIssue(jiraKey = "HHH-6614") public void testSessionCacheClear() { Session session = openSession(); session.getTransaction().begin(); StrTestEntity ste = new StrTestEntity( "data" ); session.persist( ste ); session.getTransaction().commit(); checkEmptyAuditSessionCache( session, "org.hibernate.envers.test.entities.StrTestEntity_AUD" ); }
@Test public void testJoinToSecondaryTable() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Life life = new Life(); life.duration = 15; life.fullDescription = "Long long description"; s.persist( life ); tx.commit(); s.close(); }
@Test public void testGenericGenerators() throws Exception { // Ensures that GenericGenerator annotations wrapped inside a GenericGenerators holder are bound correctly Session s = openSession(); Transaction tx = s.beginTransaction(); Monkey monkey = new Monkey(); s.persist( monkey ); s.flush(); assertNotNull( monkey.getId() ); tx.rollback(); s.close(); }
@Test(expected = TransactionRequiredException.class) public void testDeleteOutsideActiveTransaction() { Session session = openSession(); // Revision 1 session.getTransaction().begin(); StrTestEntity entity = new StrTestEntity( "data" ); session.persist( entity ); session.getTransaction().commit(); // Illegal removal of entity outside of active transaction. session.delete( entity ); session.flush(); session.close(); }
@Test(expected = PersistenceException.class) @TestForIssue(jiraKey = "HHH-12132") public void testLegacyBooleanType() throws Exception { rebuildSessionFactory( configuration -> { configuration.setProperty( "hibernate.dialect.hana.use_legacy_boolean_type", Boolean.FALSE.toString() ); } ); Session s = openSession(); s.beginTransaction(); LegacyBooleanEntity legacyEntity = new LegacyBooleanEntity(); legacyEntity.key = Integer.valueOf( 2 ); legacyEntity.bool = Boolean.FALSE; s.persist( legacyEntity ); s.flush(); s.getTransaction().commit(); s.clear(); Query<LegacyBooleanEntity> query = s.createQuery( "select b from " + LEGACY_ENTITY_NAME + " b where bool = true", LegacyBooleanEntity.class ); query.getSingleResult(); }
@Test public void testManyToMany() throws Exception { Session s = openSession(); s.getTransaction().begin(); CloudType type = new CloudType(); type.setName( "Cumulus" ); Sky sky = new Sky(); s.persist( type ); sky.getCloudTypes().add(type); s.persist( sky ); s.flush(); s.getTransaction().rollback(); s.close(); }
@Before public void init() { final Session session = openSession(); session.beginTransaction(); for ( int i = 0; i < 50; i++ ) { Product product = new Product(); product.name = "Product " + i % 10; session.persist( product ); } Truck truck1 = new Truck(); Truck truck2 = new Truck(); SportsCar sportsCar1 = new SportsCar(); session.persist( truck1 ); session.persist( truck2 ); session.persist( sportsCar1 ); session.getTransaction().commit(); session.close(); }
@Test public void testEnumKeyType() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Atmosphere atm = new Atmosphere(); atm.colorPerLevel.put( Atmosphere.Level.HIGH, "red" ); s.persist( atm ); s.flush(); s.clear(); atm = (Atmosphere) s.get( Atmosphere.class, atm.id ); assertEquals( 1, atm.colorPerLevel.size() ); assertEquals( "red", atm.colorPerLevel.get(Atmosphere.Level.HIGH) ); tx.rollback(); s.close(); }
@Test @TestForIssue(jiraKey = "HHH-12132") public void testBooleanTypeDefaultBehavior() throws Exception { rebuildSessionFactory(); Session s = openSession(); s.beginTransaction(); BooleanEntity entity = new BooleanEntity(); entity.key = Integer.valueOf( 1 ); entity.bool = Boolean.TRUE; s.persist( entity ); s.flush(); s.getTransaction().commit(); s.clear(); Query<BooleanEntity> legacyQuery = s.createQuery( "select b from " + ENTITY_NAME + " b where bool = true", BooleanEntity.class ); BooleanEntity retrievedEntity = legacyQuery.getSingleResult(); assertEquals( Integer.valueOf( 1 ), retrievedEntity.key ); assertTrue( retrievedEntity.bool ); }
private People createPeople() { Session session = openSession(); session.beginTransaction(); People people = new People(); people.people.add( new Person() ); people.people.add( new Person() ); session.persist( people ); session.getTransaction().commit(); session.close(); return people; }
@Test public void testPolymorphism() throws Exception { Car car = new Car(); car.setModel( "SUV" ); SportCar car2 = new SportCar(); car2.setModel( "350Z" ); Session s = openSession(); Transaction tx = s.beginTransaction(); s.persist( car ); s.persist( car2 ); s.flush(); assertEquals( 2, s.createQuery( "select car from Car car").list().size() ); assertEquals( 0, s.createQuery( "select count(m) from " + Automobile.class.getName() + " m").list().size() ); tx.rollback(); s.close(); }
@Test public void testEnumTypeDiscovery() { Session session = openSession(); session.beginTransaction(); UnspecifiedEnumTypeEntity entity = new UnspecifiedEnumTypeEntity( UnspecifiedEnumTypeEntity.E1.X, UnspecifiedEnumTypeEntity.E2.A ); session.persist( entity ); session.getTransaction().commit(); session.close(); }