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

The following examples show how to use org.hibernate.Session#byNaturalId() . 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 check out the related API usage on the sidebar.
Example 1
Source File: InfinispanCacheJPAFunctionalityTestEndpoint.java    From quarkus with Apache License 2.0 6 votes vote down vote up
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
Source File: InfinispanCacheJPAFunctionalityTestEndpoint.java    From quarkus with Apache License 2.0 6 votes vote down vote up
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
Source File: InfinispanCacheJPAFunctionalityTestEndpoint.java    From quarkus with Apache License 2.0 6 votes vote down vote up
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);
}