working on it ...

Filters

Explore Public Snippets

Sort by

Found 8 snippets

    public by AnghelLeonard  212360  3  5  0

    Hibernate JPA - programmatically set the transaction isolation level for the current connection

    Hibernate JPA - programmatically set the transaction isolation level for the current connection
    entityManager = entityManagerFactory.createEntityManager();
                Session session = (Session) entityManager.getDelegate();            
                session.doWork((Connection connection) -> {
                    connection.setTransactionIsolation(
                            Connection.TRANSACTION_READ_COMMITTED);
                });

    public by AnghelLeonard  1755  0  5  0

    Execute a Hibernate SQLQuery via EntityManager

    Execute a Hibernate SQLQuery via EntityManager
    List results = ((Session)this.entityManager.getDelegate()).createSQLQuery(
                    "SELECT a.name AS namep, b.name AS names, c.name AS namet"
                            + " FROM secondarycategory b"
                            + " INNER JOIN topcategory a ON a.id=b.top_id"
                            + " INNER JOIN thirdcategory c ON b.id=c.secondary_id").list();

    public by AnghelLeonard  1423  0  5  0

    SpringBoot H2 in file

    SpringBoot H2 in file
    spring.datasource.url = jdbc:h2:~/foo;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    spring.datasource.username = sa
    spring.datasource.password =

    public by AnghelLeonard  1371  0  5  0

    JUnit4 Test Suite

    JUnit4 Test Suite
    import org.junit.runner.RunWith;
    import org.junit.runners.Suite;
    
    @RunWith(Suite.class)
    @Suite.SuiteClasses({ FooTest.class, BuzzTest.class, BizzTest.class })
    public class TestSuite {
    }

    public by AnghelLeonard  1541  0  5  0

    JUnit 4 test an exception

    JUnit 4 test an exception
    @Test(expected=RuntimeException.class)
    public void fooTest() {
     throw new RuntimeException();
    }

    public by AnghelLeonard  1484  0  5  0

    EntityManager joining a JTA transaction

    EntityManager joining a JTA transaction
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo_PU");
    EntityManager em = emf.createEntityManager();
    
    // specific to JBossStandAloneJtaPlatform
    javax.transaction.TransactionManager tx = 
                    com.arjuna.ats.jta.TransactionManager.transactionManager();        
    // or
    javax.transaction.UserTransaction tx_ = 
                    com.arjuna.ats.jta.UserTransaction.userTransaction();
    
    try {
        tx.begin();
        em.joinTransaction();
        em.persist(transientInstance);
        tx.commit();
        ...

    public by AnghelLeonard  1287  0  5  0

    Hibernare evict second level cache

    Hibernare evict second level cache
    Session session = (Session) entityManager.getDelegate();
    session.getSessionFactory().getCache().evictAllRegions();

    public by AnghelLeonard  1097  0  6  0

    Convert a LocalDate to a java.sql.Date

    Convert a LocalDate to a java.sql.Date
    java.sql.Date.valueOf(local_date));

    List Complete ( 8 snippets total )

    • Public Snippets
    • Channels Snippets