我正在尝试使用 CDI-weld、JSF 2-mojarra、RichFaces 4、JPA-hibernate、Bean-Validation-hibernate、maven 2、Tomcat 7 和 Eclipse Juno 设置项目。
我认为感受最新东西的协同作用会很有趣(除了maven,懒得进入maven 3)
除了拼图中的最后一块,我让一切都像魅力一样工作,添加了 JPA。有很多关于如何设置的信息,经过一段时间的尝试,我感到非常困惑。我基本上把它缩小到这个范围:
(来自这篇文章:如果我在 Hibernate 中使用 JPA,我的项目应该有哪些依赖项?)
您需要: slf4j-jdk14 和 hibernate-entitymanager 作为工件,仅此而已?我尝试了一堆不同的设置,但没有任何效果。它只是不会生成表格。
(现在我正在尝试使用这些工件,我想我以后会担心版本)
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<!-- version 1.5.8 is the latest version that will work with the slf4j-api
that's currently bundled with hibernate-parent -->
<version>1.5.8</version>
</dependency>
persistance.xml位于:src - main - wewbapp - WEB-INF - 类 - META-INF - persistance.xml。
尝试了一堆没有运气的地方。
内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://svn.apache.org/repos/asf/geronimo/components/geronimo-schema-javaee_6/trunk/src/main/xsd/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="pu">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.test.User</class>
<properties>
<!-- Auto detect annotation model classes -->
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="1111" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/woot" />
</properties>
</persistence-unit>
</persistence>
借用测试类:
/**
* User account that is required for logging in and posting bookmarks.
*
* @author Andy Gibson
*
*/
@Entity
@Table(name = "USERS")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 24)
private String username;
@Column(length = 24,name="userPassword")
private String password;
@Column(length = 24)
private String firstName;
@Column(length = 24)
private String lastName;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Tomcat日志:
apr 21, 2012 10:58:54 EM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:\Programming\Setup\Glassfish\jdk7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;E:\Programming\Setup\Glassfish\jdk7\jre\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Microsoft Windows Performance Toolkit\;E:\Programming\Setup\Glassfish\jdk7\bin;C:\Program Files (x86)\Groovy\Groovy-1.8.0\bin;C:\Program Files (x86)\Calibre2\;E:\Programming\Setup\apache-maven-2.2.1\bin;E:\Program\SVN\bin;E:\Programming\grails-2.0.0\\bin;.
apr 21, 2012 10:58:54 EM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:woot' did not find a matching property.
apr 21, 2012 10:58:54 EM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
apr 21, 2012 10:58:54 EM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
apr 21, 2012 10:58:54 EM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 900 ms
apr 21, 2012 10:58:54 EM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
apr 21, 2012 10:58:54 EM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
apr 21, 2012 10:58:55 EM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
apr 21, 2012 10:58:55 EM org.jboss.weld.bootstrap.WeldBootstrap <clinit>
INFO: WELD-000900 1.1.5 (Final)
apr 21, 2012 10:58:55 EM org.jboss.weld.bootstrap.WeldBootstrap startContainer
INFO: WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
apr 21, 2012 10:58:56 EM org.jboss.weld.environment.tomcat7.Tomcat7Container initialize
INFO: Tomcat 7 detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported
apr 21, 2012 10:58:56 EM org.jboss.interceptor.util.InterceptionTypeRegistry <clinit>
WARNING: Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
apr 21, 2012 10:58:56 EM org.jboss.interceptor.util.InterceptionTypeRegistry <clinit>
WARNING: Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
apr 21, 2012 10:58:56 EM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.1.7 (SNAPSHOT 20120206) for context '/rdwebref'
apr 21, 2012 10:58:58 EM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
apr 21, 2012 10:58:59 EM org.hibernate.validator.util.Version <clinit>
INFO: Hibernate Validator 4.0.2.GA
apr 21, 2012 10:58:59 EM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
apr 21, 2012 10:59:00 EM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
apr 21, 2012 10:59:00 EM org.richfaces.cache.CacheManager getCacheFactory
INFO: Selected fallback cache factory
apr 21, 2012 10:59:00 EM org.richfaces.cache.lru.LRUMapCacheFactory createCache
INFO: Creating LRUMap cache instance using parameters: {javax.servlet.jsp.jstl.fmt.localizationContext=resources.application, javax.faces.STATE_SAVING_METHOD=client, javax.faces.DEFAULT_SUFFIX=.xhtml}
apr 21, 2012 10:59:00 EM org.richfaces.cache.lru.LRUMapCacheFactory createCache
INFO: Creating LRUMap cache instance of 512 items capacity
apr 21, 2012 10:59:00 EM org.richfaces.application.InitializationListener onStart
INFO: RichFaces Core Implementation by JBoss by Red Hat, version v.4.2.0.Final
apr 21, 2012 10:59:00 EM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
apr 21, 2012 10:59:00 EM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
apr 21, 2012 10:59:00 EM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6130 ms
我确实创建了名为“woot”的数据库,并且密码和用户名是正确的。我之前已经让 mysql 与 Grails 2 一起工作。
希望有人可以在这里帮助我!干杯