Search in sources :

Example 1 with Any

use of in.from.Any in project hibernate-orm by hibernate.

the class UpdateEntitiesWithPackageNamesStartingWithKeywordsTest method testUpdateEntityWithPackageNameStartingWithIn.

@Test
public void testUpdateEntityWithPackageNameStartingWithIn() {
    Any entity = new Any();
    entity.setProp("1");
    try (Session session = openSession()) {
        session.getTransaction().begin();
        try {
            session.save(entity);
            session.getTransaction().commit();
        } catch (Exception e) {
            if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                session.getTransaction().rollback();
            }
            throw e;
        }
    }
    try (Session session = openSession()) {
        session.getTransaction().begin();
        try {
            final Query query = session.createQuery("UPDATE Any set prop = :prop WHERE id = :id ");
            query.setParameter("prop", "1");
            query.setParameter("id", entity.getId());
            query.executeUpdate();
            session.getTransaction().commit();
        } catch (Exception e) {
            if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                session.getTransaction().rollback();
            }
            throw e;
        }
    }
    try (Session session = openSession()) {
        session.getTransaction().begin();
        try {
            session.createQuery("DELETE FROM Any").executeUpdate();
            session.getTransaction().commit();
        } catch (Exception e) {
            if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                session.getTransaction().rollback();
            }
            throw e;
        }
    }
}
Also used : Query(org.hibernate.query.Query) Any(in.from.Any) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Any (in.from.Any)1 Session (org.hibernate.Session)1 Query (org.hibernate.query.Query)1 Test (org.junit.Test)1