Hibernate4.3.9final FAQ Summary

Source: Internet
Author: User

Hibernate4 the next available hibernate.properties:

Jdbc.driverclassname=Com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/hibernate?characterencoding=utf-8Jdbc.username=Usernamejdbc.password=Passwordhibernate.dialect=org.hibernate.dialect.mysqldialect<!--Enable Hibernate ' s automatic session context management--># Hibernate.current_session_context_class=Threadhibernate.current_session_context_class=Org.springframework.orm.hibernate4.SpringSessionContext <!--start Cache query--hibernate.cache.use_ Query_cache=truehibernate.jdbc.batch_size=50<!--set second level-to Hibernate.cache.use_second_level_cache=True#hibernate.cache.region.factory_class=Org.hibernate.cache.ehcache.ehcacheregionfactory#hibernate.cache.provider_class=org.hibernate.cache.ehcache.EhCacheRegionFactory//Hibernate3hibernate.cache.provider_class=Org.hibernate.cache.spi.RegionFactoryhibernate.cache.region.factory_class=org.hibernate.cache.ehcache.ehcacheregionfactory<!--Drop and re-create the database schema on startup--Hib Ernate.hbm2ddl.auto=update<!--Echo all executed SQL to stdout-hibernate.show_sql=true

Related configurations in Pom.xml:

    <properties>        

Configuration for level two cache in Hibernate.properpties:
Hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.spi.RegionFactory
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
Error message:
caused by:org.hibernate.HibernateException:could not instantiate regionfactory [ Org.hibernate.cache.ehcache.EhCacheRegionFactory]
At Org.hibernate.cache.internal.RegionFactoryInitiator.initiateService (regionfactoryinitiator.java:101)
At Org.hibernate.cache.internal.RegionFactoryInitiator.initiateService (regionfactoryinitiator.java:46)
At Org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService ( standardserviceregistryimpl.java:105)
At Org.hibernate.service.internal.AbstractServiceRegistryImpl.createService (Abstractserviceregistryimpl.java : 251)
... More
caused By:org.hibernate.boot.registry.selector.spi.StrategySelectionException:Unable to resolve name [ Org.hibernate.cache.ehcache.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory]
At Org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor ( strategyselectorimpl.java:128)
At Org.hibernate.cache.internal.RegionFactoryInitiator.initiateService (regionfactoryinitiator.java:87)
... More

Causes and solutions:
Missing Jar:hibernate-ehcache
Add to:

        <dependency>            <groupId>org.hibernate</groupId>            <artifactid>hibernate-ehcache </artifactId>            <version>${hibernate-version}</version>        </dependency>



Org.hibernate.HibernateException:save is not valid without active transaction
At Org.hibernate.context.internal.threadlocalsessioncontext$transactionprotectionwrapper.invoke ( threadlocalsessioncontext.java:352)
At Com.sun.proxy. $Proxy 24.save (Unknown Source)
At Com.xx.dao.BaseDao.save (basedao.java:31)

For an error that prompts * * are not valid without active transaction
You can make the following changes in Hibernate's configuration file
<prop key= "Hibernate.current_session_context_class" > Org.springframework.orm.hibernate4.springsessioncontext</prop> (HIBERNATE4)
For hibernate3.x, you can directly remove the above settings, there will be no error, the specific reasons are unclear.
Note: Almost all normal operations must be performed under the transcation.isactive () condition. Get,load,save, saveorupdate,list all belong to this category.
http://blog.csdn.net/wzk527/article/details/8543480

Log printing:

Add slf4j jars, such as log4j, with optional Slf4j-api.jar and Slf4j-log4j12.jar

Hibernate4.3.9final FAQ Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.