hibernate connection pool

<!DOCTYPE hibernate-configuration PUBLIC “-//Hibernate/Hibernate Configuration DTD 3.0//EN” “http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”> <hibernate-configuration> <session-factory> <!– datasource config –> <property name=”connection.url”>jdbc:mysql://localhost:3306/db?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true</property> <property name=”hibernate.dialect”>org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name=”connection.driver_class”>com.mysql.jdbc.Driver</property> <property name=”connection.username”>user</property> <property name=”connection.password”>pass</property> <!– c3p0 config http://www.hibernate.org/214.html –> <property name=”connection.provider_class”>org.hibernate.connection.C3P0ConnectionProvider</property> <property name=”hibernate.c3p0.acquire_increment”>1</property> <property name=”hibernate.c3p0.idle_test_period”>60</property> <property name=”hibernate.c3p0.min_size”>1</property> <property name=”hibernate.c3p0.max_size”>2</property> <property name=”hibernate.c3p0.max_statements”>50</property> <property name=”hibernate.c3p0.timeout”>0</property> <property name=”hibernate.c3p0.acquireRetryAttempts”>1</property> <property name=”hibernate.c3p0.acquireRetryDelay”>250</property> <property name=”hibernate.show_sql”>true</property> <property name=”hibernate.use_sql_comments”>true</property> <property name=”hibernate.transaction.factory_class”>org.hibernate.transaction.JDBCTransactionFactory</property> <property name=”hibernate.current_session_context_class”>thread</property> … Read more

Hibernate unidirectional one to many association – why is a join table better?

Consider the situation where the owned entity type can also be owned by another parent entity type. Do you put foreign key references in the owned table to both parent tables? What if you have three parent types? It just doesn’t scale to large designs. A join-table decouples the join, so that the owned table … Read more

Could not write JSON: Infinite recursion (StackOverflowError); nested exception spring boot

You are facing this issue because the Statemaster model contains the object of Districtmaster model, which itself contains the object of Statemaster model. This causes an infinite json recursion. You can solve this issue by 3 methods. 1 – Create a DTO and include only the fields that you want to display in the response. … Read more

What is the MariaDB dialect class name for Hibernate?

Very short answer The current dialects as of this writing are: org.hibernate.dialect.MariaDB102Dialect for MariaDB server 10.2 org.hibernate.dialect.MariaDB103Dialect for MariaDB server 10.3 and later, provides sequence support. org.hibernate.dialect.MariaDB10Dialect for MariaDB server 10.0 and 10.1 org.hibernate.dialect.MariaDB53Dialect for MariaDB server 5.3, and later 5.x versions. org.hibernate.dialect.MariaDBDialect for MariaDB server 5.1 and 5.2. Short answer When using a MariaDB … Read more

Multiple data source and schema creation in Spring Boot

spring.jpa.hibernate.ddl-auto=create has stopped working, not because you have two DataSources, but because your application’s creating its own LocalContainerEntityManagerFactoryBeans. This has the effect of disabling the auto-configuration of a LocalContainerEntityManagerFactoryBean so you now have to configure it yourself. You can configure the two entity managers to have different schema generation behaviour like this (the first’s doing … Read more

How to rollback a database transaction when testing services with Spring in JUnit?

You need to extend transaction boundaries to the boundaries of your test method. You can do it by annotating your test method (or the whole test class) as @Transactional: @Test @Transactional public void testInsert(){ long id=myService.addPerson(“JUNIT”); assertNotNull(id); if(id<1){ fail(); } } You can also use this approach to ensure that data was correctly written before … Read more