I am using aurora mysql db. I am using mariadb connector j with hibernate. I am using "org.mariadb.jdbc.Driver".I want to set following properties of this driver using hibernate cfg file.
set read only on connetion so that it will fetch data from read replica.
pooling mechanism of mariadb driver(minPoolSize , maxPoolSize etc.)
hibernte.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- SQL Dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Database Connection Settings -->
<property name="hibernate.connection.driver_class">org.mariadb.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:aurora://xxxxx:3306/dbname</property>
<property name="hibernate.connection.username">xxxxx</property>
<property name="hibernate.connection.password">xxxxx</property>
<property name="hibernate.connection.assureReadOnly">true</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.connection.maxPoolSize">5</property>
<property name="hibernate.connection.minPoolSize">2</property>
<property name="hibernate.connection.poolName">MyConnectionPool</property>
<property name="hibernate.connection.pool">true</property>
<property name="hibernate.connection.maxIdleTime">7000</property>
<property name="show_sql">true</property>
<!-- Specifying Session Context -->
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
<!-- Mapping With Model Class Containing Annotations -->
<mapping class="com.xxx.aurora.beans.xxx" />
<mapping class="com.xxx.aurora.beans.User" />
</session-factory>
</hibernate-configuration>
I am able to connect with aurora mysql, but not able to set the connection on readonly. My requirement is that I want to create the connection with read-only replica for read queries using single cluster end point.
I am taking reference form mariadb-connector-j
I am also wondering that can I use the maria db connection pool with hibernate, if yes then how?
Change these Lines
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.connection.url">jdbc:mysql:aurora://xxxxx:3306/dbname</property>
to
<property name="dialect">org.hibernate.dialect.MariaDBDialect</property>
<property name="connection.url">jdbc:mariadb://xxxxxx:3306/dbname</property>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With