Java Code Examples for org.hibernate.Session#byNaturalId()

The following examples show how to use org.hibernate.Session#byNaturalId() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private static Statistics verifyFindCountryByNaturalId(EntityManagerFactory emf, String callingCode, String expectedName) {
    Statistics stats = getStatistics(emf);

    EntityManager em = emf.createEntityManager();
    EntityTransaction transaction = em.getTransaction();
    transaction.begin();

    final Session session = em.unwrap(Session.class);
    final NaturalIdLoadAccess<Country> loader = session.byNaturalId(Country.class);
    loader.using("callingCode", callingCode);
    Country country = loader.load();
    if (!country.getName().equals(expectedName))
        throw new RuntimeException("Incorrect citizen: " + country.getName() + ", expected: " + expectedName);

    transaction.commit();
    em.close();

    return stats;
}
 
Example 2
private static void updateNaturalId(EntityManagerFactory emf, Map<String, Counts> counts) {
    Statistics stats = getStatistics(emf);

    EntityManager em = emf.createEntityManager();
    EntityTransaction transaction = em.getTransaction();
    transaction.begin();

    final Session session = em.unwrap(Session.class);
    final NaturalIdLoadAccess<Citizen> loader = session.byNaturalId(Citizen.class);
    loader.using("ssn", "45989213T");
    Citizen citizen = loader.load();
    String expected = "Stark";
    if (!citizen.getLastname().equals(expected))
        throw new RuntimeException("Incorrect citizen: " + citizen.getLastname() + ", expected: " + expected);

    citizen.setSsn("78902007R");

    transaction.commit();
    em.close();

    assertRegionStats(counts, stats);
}
 
Example 3
private static void verifyFindCitizenByNaturalId(EntityManagerFactory emf, String ssn, String expectedLastName,
        Map<String, Counts> counts) {
    Statistics stats = getStatistics(emf);

    EntityManager em = emf.createEntityManager();
    EntityTransaction transaction = em.getTransaction();
    transaction.begin();

    final Session session = em.unwrap(Session.class);
    final NaturalIdLoadAccess<Citizen> loader = session.byNaturalId(Citizen.class);
    loader.using("ssn", ssn);
    Citizen citizen = loader.load();
    if (!citizen.getLastname().equals(expectedLastName))
        throw new RuntimeException("Incorrect citizen: " + citizen.getLastname() + ", expected: " + expectedLastName);

    transaction.commit();
    em.close();

    assertRegionStats(counts, stats);
}