1
是否可以使用Hibernate 3.6 + JPA2 + Guice-persist + Maven通過maven?Hibernate 3.6 + JPA2 + Guice-persist + Maven
我嘗試了很多設置,並沒有工作。
我注意到,hibernate-commons-annotations不再需要,但是如果排除它,我得到了Error injecting constructor, java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager
錯誤。
在這一刻,我的pom.xml看起來是這樣的:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>foo</artifactId>
<name>Foo</name>
<description>bar. </description>
<packaging>jar</packaging>
<!-- ~le propriedades com as versoes das coisas~ -->
<properties>
<hibernateVersion>3.6.10.Final</hibernateVersion>
<bval.version>0.4</bval.version>
</properties>
<!-- ~le dependencias~ -->
<dependencies>
<!-- ~ le jsr303 ~ -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella-bean-validation</artifactId>
<version>2.0-beta1</version>
</dependency>
<!-- ~ le hibernate... ~ -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateVersion}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernateVersion}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernateVersion}</version>
</dependency>
<!-- ~ le ehcache ~ -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernateVersion}</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<!-- ~ le cglib ~ -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guiceVersion}</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-persist</artifactId>
<version>${guiceVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-core</artifactId>
<version>${bval.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<version>${bval.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
而且我的persistence.xml這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="scuv" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.digitaldoc.scuv.model.Produto</class>
<class>br.com.digitaldoc.scuv.model.Cliente</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<!-- Validation modes: AUTO, CALLBACK, NONE -->
<validation-mode>AUTO</validation-mode>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1:5432/SCUV"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="postgre"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<!-- ehcache second level cache config -->
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehcache.xml"/>
<!-- c3p0 connection pool config -->
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<property name="c3p0.acquire_increment" value="1"/>
<property name="c3p0.idle_test_period" value="100"/>
<!-- seconds -->
<property name="c3p0.max_size" value="100"/>
<property name="c3p0.max_statements" value="0"/>
<property name="c3p0.min_size" value="10"/>
<property name="c3p0.timeout" value="100"/>
</properties>
</persistence-unit>
</persistence>
而且我注入我的吉斯的EntityManager。 .. 難道我做錯了什麼? 在此先感謝。