还发工具:IDEA14+jdk1.7。
文件结构以及hibernate对应的jar包:如附件中的各图所示。
persistence.xml代码:
- <persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
- version="2.0">
- <persistence-unit name="j2cmsSSH" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <properties>
- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
- <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
- <property name="hibernate.connection.username" value="root"/>
- <property name="hibernate.connection.password" value="111"/>
- <property name="hibernate.connection.url" value="jdbc:mysql://127.0.0.1:3306/j2cms-ssh?useUnicode=true&characterEncoding=utf8"/>
- <property name="hibernate.hbm2ddl.auto" value="update"/>
- <property name="hibernate.show_sql" value="true"/>
- <property name="hibernate.format_sql" value="true"/>
- <property name="hibernate.cache.region_prefix" value="org.j2cms"/>
- <property name="hibernate.cache.use_query_cache" value="true"/>
- <property name="hibernate.cache.use_second_level_cache" value="true"/>
- <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
- </properties>
- </persistence-unit>
- </persistence>
复制代码
在启动tomcat时,出现异常:Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named j2cmsSSH
具体异常信息图4所示: