Code example for Session

Methods: createSQLQuery

0
 
        // We need first to modify the columns in the middle (join table) to allow null values. Hbm2ddl doesn't seem 
        // to allow this. 
        em.getTransaction().begin();
        Session session = (Session) em.getDelegate();
        session.createSQLQuery("DROP TABLE children").executeUpdate();
        session.createSQLQuery("CREATE TABLE children(parent_id integer, child1_id integer NULL, child2_id integer NULL)").executeUpdate();
        session.createSQLQuery("DROP TABLE children_AUD").executeUpdate();
        session.createSQLQuery("CREATE TABLE children_AUD(REV integer NOT NULL, REVEND integer, REVTYPE tinyint, " +
                "parent_id integer, child1_id integer NULL, child2_id integer NULL)").executeUpdate();
        em.getTransaction().commit();
        em.clear();
 
        ParentEntity p1 = new ParentEntity("parent_1");
        ParentEntity p2 = new ParentEntity("parent_2");
 
        Child1Entity c1_1 = new Child1Entity("child1_1");
        Child1Entity c1_2 = new Child1Entity("child1_2");
 
        Child2Entity c2_1 = new Child2Entity("child2_1");
Connect your IDE to all the code out there  Get Codota for Java