org.hibernate.Session.get() - java examples

Here are the examples of the java api org.hibernate.Session.get() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : PaginationUseCases.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(Session session, Poem poem) {
    Object enreplacedy = session.get(Poem.clreplaced, poem.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

18 View Complete Implementation : MongoDBSpatialQueryTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(final Session session, final Restaurant restaurant) {
    Object enreplacedy = session.get(Restaurant.clreplaced, restaurant.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

18 View Complete Implementation : MongoDBGeoObjectTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(final Session session, final GeoObject geoObject) {
    Object enreplacedy = session.get(GeoObject.clreplaced, geoObject.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

17 View Complete Implementation : CustomerDAOImpl.java
Copyright MIT License
Author : HouariZegai
@Override
public Customer getCustomer(int customerId) {
    // get the current sessiob
    Session currentSession = sessionFactory.getCurrentSession();
    Customer customer = currentSession.get(Customer.clreplaced, customerId);
    return customer;
}

17 View Complete Implementation : MongoDBSessionCLIQueryTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(final Session session, final OscarWildePoem poem) {
    Object enreplacedy = session.get(OscarWildePoem.clreplaced, poem.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

17 View Complete Implementation : CustomerDAOImpl.java
Copyright MIT License
Author : HouariZegai
@Override
public Customer getCustomer(int customerId) {
    // get the current sessiob
    Session currentSession = sessionFactory.getCurrentSession();
    Customer customer = currentSession.get(Customer.clreplaced, customerId);
    return customer;
}

17 View Complete Implementation : Neo4jSessionNativeQueryTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(Session session, OscarWildePoem poem) {
    Object enreplacedy = session.get(OscarWildePoem.clreplaced, poem.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

17 View Complete Implementation : EmployeeDAOHibernateImpl.java
Copyright MIT License
Author : HouariZegai
@Override
public Employee findById(int id) {
    Session session = enreplacedyManager.unwrap(Session.clreplaced);
    Employee employee = session.get(Employee.clreplaced, id);
    return employee;
}

17 View Complete Implementation : MCRJPAAccessStore.java
Copyright GNU General Public License v3.0
Author : MyCoRe-Org
private static MCRACCESSRULE getAccessRule(String rid) {
    Session session = MCRHIBConnection.instance().getSession();
    return session.get(MCRACCESSRULE.clreplaced, rid);
}

17 View Complete Implementation : MongoDBSessionNativeQueryTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(Session session, OscarWildePoem poem) {
    Object enreplacedy = session.get(OscarWildePoem.clreplaced, poem.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

17 View Complete Implementation : TestHelper.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
public static <T> T get(Session session, Clreplaced<T> clazz, Serializable id) {
    return session.get(clazz, id);
}

17 View Complete Implementation : MongoDBSessionCLIQueryTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void delete(final Session session, final MarkTwainPoem poem) {
    Object enreplacedy = session.get(MarkTwainPoem.clreplaced, poem.getId());
    if (enreplacedy != null) {
        session.delete(enreplacedy);
    }
}

17 View Complete Implementation : EmployeeDAOHibernateImpl.java
Copyright MIT License
Author : HouariZegai
@Override
public Employee findById(int id) {
    Session session = enreplacedyManager.unwrap(Session.clreplaced);
    Employee employee = session.get(Employee.clreplaced, id);
    return employee;
}

16 View Complete Implementation : DeleteDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get  instructor by the primary key / id
        int idInstructor = 1;
        Instructor instructor = session.get(Instructor.clreplaced, idInstructor);
        System.out.println("Founded instructor: " + instructor);
        // delete the instructors
        if (instructor != null) {
            System.out.println("Deleting: " + idInstructor);
            // Note: we also delete replacedociated "details" object
            // because of CascadeType.ALL
            session.delete(instructor);
        }
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        factory.close();
    }
}

16 View Complete Implementation : DeleteDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get  instructor by the primary key / id
        int idInstructor = 1;
        Instructor instructor = session.get(Instructor.clreplaced, idInstructor);
        System.out.println("Founded instructor: " + instructor);
        // delete the instructors
        if (instructor != null) {
            System.out.println("Deleting: " + idInstructor);
            // Note: we also delete replacedociated "details" object
            // because of CascadeType.ALL
            session.delete(instructor);
        }
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        factory.close();
    }
}

16 View Complete Implementation : RuleResourceImpl.java
Copyright MIT License
Author : yushijinhun
private AccessRule lookupRule(String host) {
    Session session = sessionFactory.getCurrentSession();
    AccessRule rule = session.get(AccessRule.clreplaced, host);
    if (rule == null) {
        throw new NotFoundException();
    }
    return rule;
}

16 View Complete Implementation : ElementCollectionWithMapAndEmbeddedTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
@Test
public void testName() throws Exception {
    try (Session session = openSession()) {
        Transaction tx = session.beginTransaction();
        ForumUser actualUser = session.get(ForumUser.clreplaced, user.getId());
        replacedertThat(actualUser.getIssues()).includes(entry("issue1", ogmIssue1), entry("issue2", ogmIssue2));
        // We don't expect it contains this element because all attributes of the embedded are null
        replacedertThat(actualUser.getIssues()).excludes(entry("issueWithNull", ogmIssueWithNull));
        tx.commit();
    }
}

16 View Complete Implementation : DeleteStudentDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Student.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        int studentId = 1;
        // get the student for delete it
        Student student = session.get(Student.clreplaced, studentId);
        // delete student
        session.delete(student);
        // commit the transaction
        session.getTransaction().commit();
        System.out.println("Done!");
        // NEW CODE
        // start a transaction
        session = factory.getCurrentSession();
        session.beginTransaction();
        // delete all student (using HQL)
        session.createQuery("delete Student where id=2").executeUpdate();
        // commit the transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        factory.close();
    }
}

16 View Complete Implementation : AccountResourceImpl.java
Copyright MIT License
Author : yushijinhun
private Account lookupAccount(String id) {
    Session session = sessionFactory.getCurrentSession();
    Account account = session.get(Account.clreplaced, id);
    if (account == null) {
        throw new NotFoundException();
    }
    return account;
}

15 View Complete Implementation : BatchFetchingTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void cleanCondoBuilding(Session session) {
    session.beginTransaction();
    session.delete(session.get(CondominiumBuilding.clreplaced, "cb-1"));
    session.getTransaction().commit();
}

15 View Complete Implementation : BatchFetchingTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void cleanTower(Session session, Tower tower) {
    session.beginTransaction();
    session.delete(session.get(Tower.clreplaced, tower.getId()));
    for (Floor currentFloor : tower.getFloors()) {
        session.delete(session.get(Floor.clreplaced, currentFloor.getId()));
    }
    session.delete(new CondominiumBuilding("cb-1"));
    session.getTransaction().commit();
}

15 View Complete Implementation : MapElementFormulaTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testManyToManyFormula() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User gavin = new User("gavin", "secret");
    User turin = new User("turin", "tiger");
    Group g = new Group("users");
    g.getUsers().put("Gavin", gavin);
    g.getUsers().put("Turin", turin);
    s.persist(g);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    g = (Group) s.get(Group.clreplaced, "users");
    replacedertEquals(g.getUsers().size(), 2);
    g.getUsers().remove("Turin");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    g = (Group) s.get(Group.clreplaced, "users");
    replacedertEquals(g.getUsers().size(), 1);
    s.delete(g);
    s.delete(g.getUsers().get("Gavin"));
    s.delete(s.get(User.clreplaced, "turin"));
    t.commit();
    s.close();
}

15 View Complete Implementation : HibernateStatisticsTestSupport.java
Copyright Apache License 2.0
Author : hazelcast
protected Set<DummyProperty> getPropertiesOfEnreplacedy(long enreplacedyId) {
    Session session = sf.openSession();
    DummyEnreplacedy enreplacedy = session.get(DummyEnreplacedy.clreplaced, enreplacedyId);
    if (enreplacedy != null) {
        return enreplacedy.getProperties();
    } else {
        return null;
    }
}

15 View Complete Implementation : MCRHIBFileMetadataStore.java
Copyright GNU General Public License v3.0
Author : MyCoRe-Org
@Override
public MCRFilesystemNode retrieveNode(String id) throws MCRPersistenceException {
    Session session = getSession();
    MCRFSNODES node = session.get(MCRFSNODES.clreplaced, id);
    if (node == null) {
        LOGGER.warn("There is no FSNODE with ID = {}", id);
        return null;
    }
    return buildNode(node);
}

15 View Complete Implementation : DeleteHouariStudentDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).addAnnotatedClreplaced(Review.clreplaced).addAnnotatedClreplaced(Student.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the student houari from the database
        int studentId = 1;
        Student student = session.get(Student.clreplaced, studentId);
        System.out.println("Loading student: " + student);
        System.out.println("Courses: " + student.getCourses());
        // delete the student
        System.out.println("Deleting student ...");
        session.delete(student);
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

15 View Complete Implementation : HibernateKeyStore.java
Copyright Creative Commons Zero v1.0 Universal
Author : CMSgov
@Override
public String get(String macaroonID) {
    try (final Session session = this.factory.openSession()) {
        final RootKeyEnreplacedy enreplacedy = session.get(RootKeyEnreplacedy.clreplaced, macaroonID);
        if (enreplacedy == null) {
            throw new BakeryException(String.format("Cannot find root key for Macaroon ID %s", macaroonID));
        }
        return enreplacedy.getRootKey();
    }
}

15 View Complete Implementation : EagerLazyDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the instructor from db
        int idInstructor = 1;
        Instructor instructor = session.get(Instructor.clreplaced, idInstructor);
        System.out.println("houari: Instructor: " + instructor);
        // option 1: call getter method while session is open
        // get courses for the instructor
        // demand the course before close the session (work fine)
        System.out.println("houari: Courses: " + instructor.getCourse());
        // commit transaction
        session.getTransaction().commit();
        // close the session
        session.close();
        System.out.println("\nHouari: The session in now closed!\n");
        // since course are lazy loaded ... this should fail
        // update: because i call the getter method above before close the session, i solve the issue of lazy fetch :D
        // get courses for the instructor
        System.out.println("houari: Courses: " + instructor.getCourse());
        System.out.println("houari: Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

15 View Complete Implementation : GetCoursesForHouariDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).addAnnotatedClreplaced(Review.clreplaced).addAnnotatedClreplaced(Student.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the student houari from the database
        int studentId = 1;
        Student student = session.get(Student.clreplaced, studentId);
        System.out.println("Loading student: " + student);
        System.out.println("Courses: " + student.getCourses());
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

15 View Complete Implementation : UpdateStudentDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Student.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        int studentId = 1;
        // get the student for update it
        Student student = session.get(Student.clreplaced, studentId);
        // updating student...
        student.setFirstName("Fares");
        // commit the transaction
        session.getTransaction().commit();
        System.out.println("Done!");
        // NEW CODE
        // start a transaction
        session = factory.getCurrentSession();
        session.beginTransaction();
        // upadate all student (using HQL)
        session.createQuery("update Student set email='[email protected]' where email LIKE '%@houarizegai.com'").executeUpdate();
        // commit the transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        factory.close();
    }
}

15 View Complete Implementation : GetInstructorCoursesDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the instructor from db
        int idInstructor = 1;
        Instructor instructor = session.get(Instructor.clreplaced, idInstructor);
        System.out.println("Instructor: " + instructor);
        // get courses for the instructor
        System.out.println("Courses: " + instructor.getCourse());
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

15 View Complete Implementation : MCRHIBFileMetadataStore.java
Copyright GNU General Public License v3.0
Author : MyCoRe-Org
@Override
public void deleteNode(String id) throws MCRPersistenceException {
    Session session = getSession();
    MCRFSNODES node = session.get(MCRFSNODES.clreplaced, id);
    if (node != null) {
        // MCR-1634
        session.delete(node);
    }
}

15 View Complete Implementation : GetInstructorCoursesDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the instructor from db
        int idInstructor = 1;
        Instructor instructor = session.get(Instructor.clreplaced, idInstructor);
        System.out.println("Instructor: " + instructor);
        // get courses for the instructor
        System.out.println("Courses: " + instructor.getCourse());
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

15 View Complete Implementation : JPAProxyTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
/**
 * The ejb3 find() method maps to the Hibernate get() method
 */
public void testGetSemantics() {
    Long nonExistentId = new Long(-1);
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    Item item = (Item) s.get(Item.clreplaced, nonExistentId);
    replacedertNull("get() of non-existent enreplacedy did not return null", item);
    txn.commit();
    s.close();
    s = openSession();
    txn = s.beginTransaction();
    // first load() it to generate a proxy...
    item = (Item) s.load(Item.clreplaced, nonExistentId);
    replacedertFalse(Hibernate.isInitialized(item));
    // then try to get() it to make sure we get an exception
    try {
        s.get(Item.clreplaced, nonExistentId);
        fail("force load did not fail on non-existent enreplacedy");
    } catch (EnreplacedyNotFoundException e) {
    // expected behavior
    } catch (replacedertionFailedError e) {
        throw e;
    } catch (Throwable t) {
        fail("unexpected exception type on non-existent enreplacedy force load : " + t);
    }
    txn.commit();
    s.close();
}

14 View Complete Implementation : ReadStudentDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Student.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // use the session object to save Java object
        System.out.println("Creating new student object...");
        // create student object
        Student student = new Student("Houari", "ZEGAI", "[email protected]");
        // start a transaction
        session.beginTransaction();
        // save the student object
        System.out.println("Saving the student...");
        session.save(student);
        System.out.println(student);
        // commit transaction
        session.getTransaction().commit();
        // read data from database (get data)
        // find out the student's id: primary key
        System.out.println("Saved student. Generated id: " + student.getId());
        // now get a new session and start transaction
        session = factory.getCurrentSession();
        session.beginTransaction();
        // retrieve student based on the id: primary key
        System.out.println("Getting student with id: " + student.getId());
        Student mStudent = session.get(Student.clreplaced, student.getId());
        System.out.println("Get complete: " + mStudent);
        // commit the transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        factory.close();
    }
}

14 View Complete Implementation : DeleteCoursesDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the course from the db
        int idCourse = 10;
        Course course = session.get(Course.clreplaced, idCourse);
        System.out.println("Deleting course: " + course);
        // delete the course
        session.delete(course);
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : OptimisticLockingExtraTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
@Test
public void updateToEmbeddedCollectionCausesVersionToBeIncreased() throws Throwable {
    Galaxy galaxy = persistGalaxy();
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    Galaxy enreplacedy = session.get(Galaxy.clreplaced, galaxy.getId());
    enreplacedy.getStars().add(new Star("Algol"));
    transaction.commit();
    session.clear();
    session = openSession();
    transaction = session.beginTransaction();
    enreplacedy = session.get(Galaxy.clreplaced, galaxy.getId());
    replacedertThat(enreplacedy.getVersion()).isEqualTo(1);
    replacedertThat(enreplacedy.getStars()).hreplacedize(3);
    transaction.commit();
    session.close();
}

14 View Complete Implementation : AuctionTest2.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testLazy() {
    if (!getDialect().supportsExistsInSelect()) {
        reportSkip("dialect does not support exist fragments in the select clause", "bidi support");
        return;
    }
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Auction a = new Auction();
    a.setDescription("an auction for something");
    a.setEnd(new Date());
    Bid b = new Bid();
    b.setAmount(new BigDecimal(123.34).setScale(19, BigDecimal.ROUND_DOWN));
    b.setSuccessful(true);
    b.setDatetime(new Date());
    b.sereplacedem(a);
    a.getBids().add(b);
    a.setSuccessfulBid(b);
    s.persist(b);
    t.commit();
    s.close();
    Long aid = a.getId();
    Long bid = b.getId();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    replacedertFalse(Hibernate.isInitialized(b));
    a = (Auction) s.get(Auction.clreplaced, aid);
    replacedertFalse(Hibernate.isInitialized(a.getBids()));
    replacedertFalse(Hibernate.isInitialized(a.getSuccessfulBid()));
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertSame(b, a.getSuccessfulBid());
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    replacedertFalse(Hibernate.isInitialized(b));
    a = (Auction) s.createQuery("from Auction a left join fetch a.bids").uniqueResult();
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertTrue(Hibernate.isInitialized(a.getBids()));
    replacedertSame(b, a.getSuccessfulBid());
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    a = (Auction) s.load(Auction.clreplaced, aid);
    replacedertFalse(Hibernate.isInitialized(b));
    replacedertFalse(Hibernate.isInitialized(a));
    s.createQuery("from Auction a left join fetch a.successfulBid").list();
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertTrue(Hibernate.isInitialized(a));
    replacedertSame(b, a.getSuccessfulBid());
    replacedertFalse(Hibernate.isInitialized(a.getBids()));
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    a = (Auction) s.load(Auction.clreplaced, aid);
    replacedertFalse(Hibernate.isInitialized(b));
    replacedertFalse(Hibernate.isInitialized(a));
    replacedertSame(s.get(Bid.clreplaced, bid), b);
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertSame(s.get(Auction.clreplaced, aid), a);
    replacedertTrue(Hibernate.isInitialized(a));
    replacedertSame(b, a.getSuccessfulBid());
    replacedertFalse(Hibernate.isInitialized(a.getBids()));
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
}

14 View Complete Implementation : AuctionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testLazy() {
    if (getDialect() instanceof PostgreSQLDialect) {
        // doesn't like boolean=1
        return;
    }
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Auction a = new Auction();
    a.setDescription("an auction for something");
    a.setEnd(new Date());
    Bid b = new Bid();
    b.setAmount(new BigDecimal(123.34).setScale(19, BigDecimal.ROUND_DOWN));
    b.setSuccessful(true);
    b.setDatetime(new Date());
    b.sereplacedem(a);
    a.getBids().add(b);
    a.setSuccessfulBid(b);
    s.persist(b);
    t.commit();
    s.close();
    Long aid = a.getId();
    Long bid = b.getId();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    replacedertFalse(Hibernate.isInitialized(b));
    a = (Auction) s.get(Auction.clreplaced, aid);
    replacedertFalse(Hibernate.isInitialized(a.getBids()));
    replacedertTrue(Hibernate.isInitialized(a.getSuccessfulBid()));
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertSame(b, a.getSuccessfulBid());
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    replacedertFalse(Hibernate.isInitialized(b));
    a = (Auction) s.createQuery("from Auction a left join fetch a.bids").uniqueResult();
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertTrue(Hibernate.isInitialized(a.getBids()));
    replacedertSame(b, a.getSuccessfulBid());
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    a = (Auction) s.load(Auction.clreplaced, aid);
    replacedertFalse(Hibernate.isInitialized(b));
    replacedertFalse(Hibernate.isInitialized(a));
    s.createQuery("from Auction a left join fetch a.successfulBid").list();
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertTrue(Hibernate.isInitialized(a));
    replacedertSame(b, a.getSuccessfulBid());
    replacedertFalse(Hibernate.isInitialized(a.getBids()));
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    b = (Bid) s.load(Bid.clreplaced, bid);
    a = (Auction) s.load(Auction.clreplaced, aid);
    replacedertFalse(Hibernate.isInitialized(b));
    replacedertFalse(Hibernate.isInitialized(a));
    replacedertSame(s.get(Bid.clreplaced, bid), b);
    replacedertTrue(Hibernate.isInitialized(b));
    replacedertSame(s.get(Auction.clreplaced, aid), a);
    replacedertTrue(Hibernate.isInitialized(a));
    replacedertSame(b, a.getSuccessfulBid());
    replacedertFalse(Hibernate.isInitialized(a.getBids()));
    replacedertSame(a.getBids().iterator().next(), b);
    replacedertTrue(b.isSuccessful());
    t.commit();
    s.close();
}

14 View Complete Implementation : DeleteInstructorDetailDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the instructor detail object
        int instructorDetailId = 3;
        InstructorDetail instructorDetail = session.get(InstructorDetail.clreplaced, instructorDetailId);
        // now let's delete instructor detail
        System.out.println("Deleting instructor detail: " + instructorDetail);
        // remove the replacedociation object reference
        instructorDetail.getInstructor().setInstructorDetail(null);
        session.delete(instructorDetail);
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } catch (HibernateException he) {
        he.printStackTrace();
    } finally {
        // handle connection leak issue
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : LoginServiceImpl.java
Copyright MIT License
Author : yushijinhun
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Override
public Account loginWithPreplacedword(String username, String preplacedword, boolean ignoreBanned) throws ForbiddenOperationException {
    if (username == null || preplacedword == null) {
        throw new ForbiddenOperationException(MSG_INVALID_USERNAME_OR_PreplacedWORD);
    }
    Session session = sessionFactory.getCurrentSession();
    Account account = session.get(Account.clreplaced, username);
    if (account == null || account.getPreplacedword() == null || !preplacedwordAlgorithm.verify(preplacedword, account.getPreplacedword())) {
        throw new ForbiddenOperationException(MSG_INVALID_USERNAME_OR_PreplacedWORD);
    }
    if (!ignoreBanned && account.isBanned()) {
        throw new ForbiddenOperationException(MSG_ACCOUNT_BANNED);
    }
    return account;
}

14 View Complete Implementation : ProfileResourceImpl.java
Copyright MIT License
Author : yushijinhun
private GameProfile lookupProfile(UUID uuid) {
    Session session = sessionFactory.getCurrentSession();
    GameProfile profile = session.get(GameProfile.clreplaced, uuid.toString());
    if (profile == null) {
        throw new NotFoundException();
    }
    return profile;
}

14 View Complete Implementation : ReferencedCompositeIdTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
@Test
public void testManyToManyReferenceWithCompositeId() throws Exception {
    final Session session = openSession();
    Transaction transaction = session.beginTransaction();
    Tournament britishOpen = new Tournament(new TournamentId("US", "123"), "British Open");
    Tournament playersChampionship = new Tournament(new TournamentId("US", "456"), "Player's Championship");
    session.persist(britishOpen);
    session.persist(playersChampionship);
    // persist object with replacedociation
    Director bob = new Director("bob", "Bob", null);
    bob.getAttendedTournaments().add(britishOpen);
    bob.getAttendedTournaments().add(playersChampionship);
    session.persist(bob);
    transaction.commit();
    session.clear();
    // replacedert replacedociation, remove one element
    transaction = session.beginTransaction();
    Director loadedParticipant = (Director) session.get(Director.clreplaced, "bob");
    replacedertThat(bob.getAttendedTournaments()).onProperty("name").contains("British Open", "Player's Championship");
    loadedParticipant.getAttendedTournaments().remove(session.get(Tournament.clreplaced, britishOpen.getId()));
    transaction.commit();
    session.clear();
    // element should have been removed
    transaction = session.beginTransaction();
    loadedParticipant = (Director) session.get(Director.clreplaced, "bob");
    replacedertThat(bob.getAttendedTournaments()).onProperty("name").contains("Player's Championship");
    transaction.commit();
    session.clear();
    transaction = session.beginTransaction();
    loadedParticipant = (Director) session.get(Director.clreplaced, "bob");
    session.delete(loadedParticipant);
    session.delete(session.get(Tournament.clreplaced, britishOpen.getId()));
    session.delete(session.get(Tournament.clreplaced, playersChampionship.getId()));
    transaction.commit();
}

14 View Complete Implementation : GetCourseAndReviewsDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).addAnnotatedClreplaced(Review.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the course
        int idCourse = 10;
        Course course = session.get(Course.clreplaced, idCourse);
        System.out.println("Deleting the course: " + course);
        // delete the course
        session.delete(course);
        // PS: automatic delete all reviews related with this course (because we make cascade type: ALL)
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : GetInstructorDetailDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the instructor detail object
        int instructorDetailId = 12;
        InstructorDetail instructorDetail = session.get(InstructorDetail.clreplaced, instructorDetailId);
        // print the instructor detail
        System.out.println("Instructor detail: " + instructorDetail);
        // print the replacedociated instructor
        System.out.println("replacedociated Instructor: " + instructorDetail.getInstructor());
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } catch (HibernateException he) {
        he.printStackTrace();
    } finally {
        // handle connection leak issue
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : DeleteCoursesDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the course from the db
        int idCourse = 10;
        Course course = session.get(Course.clreplaced, idCourse);
        System.out.println("Deleting course: " + course);
        // delete the course
        session.delete(course);
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : DeleteCourseAndReviewsDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).addAnnotatedClreplaced(Review.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the course
        int idCourse = 10;
        Course course = session.get(Course.clreplaced, idCourse);
        // print the course
        System.out.println("Course: " + course);
        // print the course reviews
        System.out.println("Reviews: " + course.getReviews());
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : ReferencedCompositeIdTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
@Test
public void testManyToOneReferenceWithCompositeId() throws Exception {
    final Session session = openSession();
    Transaction transaction = session.beginTransaction();
    Tournament britishOpen = new Tournament(new TournamentId("US", "123"), "British Open");
    Tournament playersChampionship = new Tournament(new TournamentId("US", "456"), "Player's Championship");
    session.persist(britishOpen);
    session.persist(playersChampionship);
    // persist object with replacedociation
    Director bob = new Director("bob", "Bob", playersChampionship);
    session.persist(bob);
    transaction.commit();
    session.clear();
    // replacedert and un-set the replacedociation
    transaction = session.beginTransaction();
    Director loadedParticipant = (Director) session.get(Director.clreplaced, "bob");
    replacedertThat(bob.getDirectedTournament().getName()).isEqualTo("Player's Championship");
    bob.setDirectedTournament(null);
    transaction.commit();
    session.clear();
    // replacedociation should have been removed
    transaction = session.beginTransaction();
    loadedParticipant = (Director) session.get(Director.clreplaced, "bob");
    replacedertThat(bob.getDirectedTournament()).isNull();
    transaction.commit();
    session.clear();
    transaction = session.beginTransaction();
    loadedParticipant = (Director) session.get(Director.clreplaced, "bob");
    session.delete(loadedParticipant.getDirectedTournament());
    session.delete(loadedParticipant);
    session.delete(session.get(Tournament.clreplaced, britishOpen.getId()));
    transaction.commit();
}

14 View Complete Implementation : DeleteCourseDemo.java
Copyright MIT License
Author : HouariZegai
public static void main(String[] args) {
    // create session factory
    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClreplaced(Instructor.clreplaced).addAnnotatedClreplaced(InstructorDetail.clreplaced).addAnnotatedClreplaced(Course.clreplaced).addAnnotatedClreplaced(Review.clreplaced).addAnnotatedClreplaced(Student.clreplaced).buildSessionFactory();
    // create session
    Session session = factory.getCurrentSession();
    try {
        // start a transaction
        session.beginTransaction();
        // get the course u wanna delete it from database
        int courseId = 12;
        Course course = session.get(Course.clreplaced, courseId);
        // delete the course
        System.out.println("Deleting the course ...");
        session.delete(course);
        // commit transaction
        session.getTransaction().commit();
        System.out.println("Done!");
    } finally {
        // clean up code
        session.close();
        factory.close();
    }
}

14 View Complete Implementation : GetLoadTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testGetLoad() {
    clearCounts();
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Employer emp = new Employer();
    s.persist(emp);
    Node node = new Node("foo");
    Node parent = new Node("bar");
    parent.addChild(node);
    s.persist(parent);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.get(Employer.clreplaced, emp.getId());
    replacedertTrue(Hibernate.isInitialized(emp));
    replacedertFalse(Hibernate.isInitialized(emp.getEmployees()));
    node = (Node) s.get(Node.clreplaced, node.getName());
    replacedertTrue(Hibernate.isInitialized(node));
    replacedertFalse(Hibernate.isInitialized(node.getChildren()));
    replacedertFalse(Hibernate.isInitialized(node.getParent()));
    replacedertNull(s.get(Node.clreplaced, "xyz"));
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.load(Employer.clreplaced, emp.getId());
    emp.getId();
    replacedertFalse(Hibernate.isInitialized(emp));
    node = (Node) s.load(Node.clreplaced, node.getName());
    replacedertEquals(node.getName(), "foo");
    replacedertFalse(Hibernate.isInitialized(node));
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.get("org.hibernate.test.ops.Employer", emp.getId());
    replacedertTrue(Hibernate.isInitialized(emp));
    node = (Node) s.get("org.hibernate.test.ops.Node", node.getName());
    replacedertTrue(Hibernate.isInitialized(node));
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.load("org.hibernate.test.ops.Employer", emp.getId());
    emp.getId();
    replacedertFalse(Hibernate.isInitialized(emp));
    node = (Node) s.load("org.hibernate.test.ops.Node", node.getName());
    replacedertEquals(node.getName(), "foo");
    replacedertFalse(Hibernate.isInitialized(node));
    tx.commit();
    s.close();
    replacedertFetchCount(0);
}

13 View Complete Implementation : EmbeddableTest.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
@Test
public void testNestedEmbeddable() {
    final Session session = openSession();
    // persist enreplacedy without the embeddables
    Transaction transaction = session.beginTransaction();
    Account account = new Account();
    account.setLogin("gunnar");
    session.persist(account);
    transaction.commit();
    session.clear();
    // read back
    transaction = session.beginTransaction();
    Account loadedAccount = (Account) session.get(Account.clreplaced, account.getLogin());
    replacedertThat(loadedAccount).as("Cannot load persisted object with nested embeddables which are null").isNotNull();
    replacedertThat(loadedAccount.getHomeAddress()).isNull();
    // update
    loadedAccount.setHomeAddress(new Address());
    loadedAccount.getHomeAddress().setCity("Lima");
    loadedAccount.getHomeAddress().setType(new AddressType("primary"));
    transaction.commit();
    session.clear();
    // read back nested embeddable
    transaction = session.beginTransaction();
    loadedAccount = (Account) session.get(Account.clreplaced, account.getLogin());
    replacedertThat(loadedAccount).as("Cannot load persisted object with nested embeddables").isNotNull();
    replacedertThat(loadedAccount.getHomeAddress()).isNotNull();
    replacedertThat(loadedAccount.getHomeAddress().getCity()).isEqualTo("Lima");
    replacedertThat(loadedAccount.getHomeAddress().getType()).isNotNull();
    replacedertThat(loadedAccount.getHomeAddress().getType().getName()).isEqualTo("primary");
    session.delete(loadedAccount);
    transaction.commit();
    session.clear();
    transaction = session.beginTransaction();
    replacedertThat(session.get(Account.clreplaced, account.getLogin())).isNull();
    transaction.commit();
    session.close();
}