public class HibernateConnector extends Connector implements DedicatedConnectionSupport
Hibernate connector is used to integrate Hibernate framework with jPALIO. There is possible to define many Hibernate connectors in one jPALIO instance.
Hibernate connector configuration
There are two ways to configure hibernate connector
Environment
class. configFile
(above) parameter is not specified.
If mapping classes sources are stored in jPALIO objects, there is no need to specify mapping classes in connector configuration (
mapClasses
). For that classes special object type should be used: JPA Mapping Class. While configuring/reconfiguring
all jPALIO objects with this type are selected from database and added to the configuration (only assigned to the connector - see below).
Parameters from connector configuration are more important than parameters from Hibernate configuration file/object. Parameters from config file/object will be overwritten by connector parameters.
IMPORTANT! All mapping classes must be assigned to any connector. The assignement must be made by Assigned
annotation. If
not assigned, class will be omitted.
@Assigned(connector="hibernate")
<connector name="hibernate" url="jdbc:postgresql://localhost:5432/dbname" class="HibernateConnector"> <mappingMethod>annotation</mappingMethod> <configFile>/opt/jpalio/instances/lechpol_hibernate.cfg.xml</configFile> <user>db_user</user> <password>db_password</password> <driver>org.postgresql.Driver</driver> <hibernateLoggerLevel>ERROR</hibernateLoggerLevel> <mapClasses> lechpol.model.Address; lechpol.model.BankAccount; lechpol.model.Client; lechpol.model.Config; lechpol.model.Department; lechpol.model.Employee; lechpol.model.Material; lechpol.model.MaterialGroup; lechpol.model.MaterialStorage; lechpol.model.Model </mapClasses> </connector>
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">org.postgresql.Driver</property> <property name="connection.url">jdbc:postgresql://localhost:5432/dbname</property> <property name="connection.username">db_user</property> <property name="connection.password">db_password</property> <!-- Use the C3P0 connection pool. Default Hibernate connection pooling mechanism shuldn't be used in production environment --> <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="hibernate.c3p0.min_size">3</property> <property name="hibernate.c3p0.max_size">10</property> <property name="hibernate.c3p0.timeout">1800</property> <!-- Disable second-level cache. --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="cache.use_query_cache">false</property> <property name="cache.use_minimal_puts">false</property> <property name="max_fetch_depth">3</property> <!-- JDBC connection pool (use the built-in) --> <!-- <property name="connection.pool_size">1</property> --> <!-- SQL dialect --> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <!-- Bind the getCurrentSession() method to the thread. --> <property name="current_session_context_class">thread</property> <!-- <property name="hibernate.show_sql">true</property> --> <!-- <property name="hibernate.format_sql">true</property> --> <!-- Only for development environment --> <!--<property name="hibernate.hbm2ddl.auto">update</property>--> </session-factory> </hibernate-configuration>
configFile
(above) parameter is not specified.Hibernate connector can be used in jPALIO SQL transaction mechanism.
Sql sql = Groovy.module("sql") try { sql.transactionStart() sql.trasanctionAdd("hibernate", "data") .. // Hibernate session operations // Old school sql.write ... .. sql.commit() } catch(Exception ex) { sql.rollback() } finally { sql.transactionStop() }
Assigned
cluster, connectorClass, instance, name, properties, refreshInterval, scheduler, sharedConfiguration, url
Constructor and Description |
---|
HibernateConnector(java.lang.String url,
java.util.Properties properties) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
dedicatedCommit() |
void |
dedicatedRollback() |
void |
dedicatedStart() |
void |
dedicatedStop() |
org.hibernate.Session |
getCurrentSession()
Returns current hibernate session
|
org.hibernate.Session |
getNewSession()
Returns new hibernate session
|
void |
init() |
boolean |
isTransaction() |
void |
refresh() |
delete, getAsPalioConnector, getConnector, getConnector, getInfo, getInstance, getLogConfiguration, getName, getUrl, info, info, init, log, logDebug, logError, logError, logWarning, save, scheduler, setDedicatedLogConfiguration, setInstance
public HibernateConnector(java.lang.String url, java.util.Properties properties)
public org.hibernate.Session getCurrentSession()
public org.hibernate.Session getNewSession()
public void init() throws PalioException
init
in class Connector
PalioException
public void refresh() throws PalioException
refresh
in class Connector
PalioException
public void dedicatedCommit() throws PalioException
dedicatedCommit
in interface DedicatedConnectionSupport
PalioException
public void dedicatedRollback() throws PalioException
dedicatedRollback
in interface DedicatedConnectionSupport
PalioException
public void dedicatedStart() throws PalioException
dedicatedStart
in interface DedicatedConnectionSupport
PalioException
public void dedicatedStop() throws PalioException
dedicatedStop
in interface DedicatedConnectionSupport
PalioException
public boolean isTransaction() throws PalioException
isTransaction
in interface DedicatedConnectionSupport
PalioException