누구나 Hibernate 4와 MySQL 5.1을 사용하는 hibernate.cfg.xml 설정 파일의 예제를 가지고 있습니까? 나는 메이븐 (3.0.3) 웹 프로젝트를 가지고 있고 내 JUnit 테스트를 실행할 때, 테스트는 ... 심지어 테이블, 사용자가 존재하지만 예외와 함께 실패 여기 MySQL 5.1에서 Hibernate 4를 설정하는데 문제가있다.
org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table: USERS
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:875)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:710)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3406)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3360)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1334)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at com.myco.eventmaven.dao.UsersDaoImpl.<init>(UsersDaoImpl.java:27)
at com.myco.eventmaven.dao.UsersDaoImplTest.setUpStaticVars(UsersDaoImplTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
내 hibernate.cfg입니다 .XML 파일은 ...
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/eventmaven</property>
<property name="hibernate.connection.username">eventmaven</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="com.myco.eventmaven.domain.Registration" />
</session-factory>
</hibernate-configuration>
어떤 호기심 것은 내가 절대적으로 잘못된 값으로 URL, 사용자 이름 또는 암호를 변경하는 경우에도 같은 예외가 있다는 것입니다. 저는 여기에 결합하기 위해 노력하고있어 클래스의 선언 ...
package com.myco.eventmaven.domain;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Table;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
@Entity
@Table(appliesTo = "USERS")
public class Registration implements Serializable {
@Id
@Column(name = "ID")
Integer id;
@Column(name = "USERNAME")
private String userName;
@NotEmpty
@Size(min = 4, max = 20)
@Column(name = "PASSWORD")
private String password;
@NotEmpty
private String confirmPassword;
@NotEmpty
private String salt;
@NotEmpty
@Email
@Column(name = "EMAIL")
private String email;
@Column(name = "FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
public String getConfirmPassword() {
return confirmPassword;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
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;
}
}
덕분입니다 - 데이브
1) 유닉스를 사용하고 있습니까? 2) JUnit 외부에서 작동합니까/웹 응용 프로그램에서 Eclipse /에서 테스트를 실행할 때, 즉 문제가 발생했는지 또는 모든 곳에서 발생합니까? –