|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
SessionFactoryBuilder | Utility interface to build Hibernate SessionFactory . |
SessionsRepository | Interface implemented by the object returned by
HibernateTransactionService.getCurrentTransaction . |
Class Summary | |
---|---|
HibernateMappingContribution | Represents a mapping element of a HibernateSettingsSchema . |
HibernateTransactionService | Service managing Hibernate sessions & transactions, without JTA. |
SessionFactoryBuilderImpl | Utility class to build Hibernate SessionFactory . |
SessionFactoryContribution | Represents a configuration parameter to the SessionProxyFactory
configured for building a Session service. |
SessionProxyFactory | This service creates Proxys to Hibernate Sessions. |
SessionsRepositoryImpl | Actual implementation class for SessionsRepository . |
SessionsRepositoryImpl.TransactionEntry |
This is the main package for Hibernate-specific transaction handling under HiveMind.
It implements the TransactionService specifically for Hibernate 3 Sessions.Session
into the application services.HibernateTransactionService
can work with more than one SessionFactory at the same time.
HibernateTransactionService
creates Hibernate3 Session
s from a standard Hibernate SessionFactory
that it builds according to configuration passed at construction time of the Session
service.<service-point id="MySession" interface="org.hibernate.Session"> <invoke-factory service-id="hivetranse.hibernate3.SessionFactory" model="singleton"> <config file="hibernate-config.xml"> <property name="hibernate.connection.url" value="jdbc:mysql://localhost/test"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="xxx"/> </config> </invoke-factory> </service-point>Please note that, although it may sound strange at first sight, this service must use the
singleton
service model.SymbolSource
s), in order to avoid hard-code, in the Hibernate configuration file, properties that may change on different environments , for instance, the url to the database used (it will differ between integration, acceptance and production environments), along with the password of the user to access it, as shown in the above example.<contribution configuration-id="hivemind.EagerLoad"> <load service-id="MySession"/> </contribution>Such a
Session
service can then be injected in your services that need it.
Those services just need to use the injected Session
in a usual way, as if it had been obtained directly from a Hibernate SessionFactory
that you had built by yourself, with the exception that the code of your service should never call methods that deal with transactions (this is taken care of by the TransactionService
) or close the Session
.hivetranse.hibernate3.HibernateSettingsSchema
schema, and contribute mappings and properties to this configuration point, as the following example shows:
<configuration-point id="MyHibernateSettings" occurs="1..n" schema-id="hivetranse.hibernate3.HibernateSettingsSchema"/> <contribution configuration-id="MyHibernateSettings"> <mapping class="example.domain.Address"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> ... </contribution> <service-point id="MySession" interface="org.hibernate.Session"> <invoke-factory service-id="hivetranse.hibernate3.SessionFactory" model="singleton"> <config configuration-id="MyHibernateSettings"> <property name="hibernate.connection.url" value="${db.test.url}"/> <property name="hibernate.connection.username" value="${db.test.user}"/> <property name="hibernate.connection.password" value="${db.test.password}"/> </config> </invoke-factory> </service-point>As you can see, it is still possible to define Hibernate properties in two locations: in contributions to the configuration point and also directly in the parameters passed to
hivetranse.hibernate3.SessionFactory
. In case a same parameter is defined in both locations, then the value for the configuration point is used.hivetranse.hibernate3.SessionFactory
.
HibernateTransactionService
to build Hibernate SessionFactory
s.hivetranse.hibernate3
module, the implementation is not. The implementation must be declared in your own application module. The declaration must always be exactly the same as follows:
<implementation service-id="hivetranse.hibernate3.SessionFactoryBuilder"> <invoke-factory model="primitive"> <construct class="net.sourceforge.hivetranse.transaction.hibernate3.SessionFactoryBuilderImpl"> <log/> </construct> </invoke-factory> </implementation>Why is this implementation not directly declared in
hivetranse.hibernate3
module configuration file? This is for technical reasons: implementation had to be parted from the module declaration in order to perform better unit testing of the hivetranse.hibernate3
module.HibernateTransactionService
is not based on JTA, it is still possible to define more than one SessionFactory, hence more than one Session service (each built from a different Sessionfactory, ie pointing to a different database).HibernateTransactionService
will try to commit (or rollback) all the Sessions transactions at the same time, but if one commit (or rollback) fails after the previous one has succeeded, then the resulting state of all databases will probably be inconsistent.HibernateTransactionService
.
|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |