您
persistence.xml的用户名无效,
EntityManagerFactory因此无法创建。它应该是:
<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_1_0.xsd" version="1.0"> <persistence-unit name="customerManager" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>Customer</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="1234"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/general"/> <property name="hibernate.max_fetch_depth" value="3"/> </properties> </persistence-unit></persistence>
(请注意
<property>元素是如何关闭的,不应嵌套)
更新:
我遍历了本教程,
Id使用MySQL时,您还必须更改生成策略(因为MySQL不支持序列)。我建议使用该
AUTO策略(MySQL默认为IDENTITY)。为此,请删除
SequenceGenerator注释并按如下所示更改代码:
@Entity@Table(name="TAB_CUSTOMER")public class Customer implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="CUSTOMER_ID", precision=0) private Long customerId = null; ...}这应该有所帮助。
PS:您还应该提供一个
log4j.properties建议。



