package com.maroclance.university.service;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ModuleServiceTest {
public class ModuleServiceTest {
private static ClassPathXmlApplicationContext context;
private static ModuleService moduleService;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
context = new ClassPathXmlApplicationContext("application-context.xml");
moduleService=(ModuleService) context.getBean("moduleService");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
context.close();
}
@Test
public void test() {
fail("Not yet implemented");
}
}
我发出不使用moduleService的警告 当我执行我的代码时,我有这个错误
rg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.maroclance.model.Matiere.profMats[com.maroclance.model.ProfMat]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
.
.
.
.
aused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.maroclance.model.Matiere.profMats[com.maroclance.model.ProfMat]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1068)
我真的被阻止了
答案 0 :(得分:0)
package com.maroclance.university.model;
// Generated 19 sept. 2014 13:34:26 by Hibernate Tools 3.4.0.CR1
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* Matiere generated by hbm2java
*/
@SuppressWarnings("serial")
@Entity
@Table(name = "matiere", catalog = "gestionmatiere")
public class Matiere implements java.io.Serializable {
private int id;
private String nomMatiere;
private int coefficient;
private Set<ProfMat> profMats = new HashSet<ProfMat>(0);
private Set<Module> modules = new HashSet<Module>(0);
public Matiere() {
}
public Matiere(int id, String nomMatiere, int coefficient) {
this.id = id;
this.nomMatiere = nomMatiere;
this.coefficient = coefficient;
}
public Matiere(int id, String nomMatiere, int coefficient,
Set<ProfMat> profMats, Set<Module> modules) {
this.id = id;
this.nomMatiere = nomMatiere;
this.coefficient = coefficient;
this.profMats = profMats;
this.modules = modules;
}
@Id
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "nom_matiere", nullable = false, length = 20)
public String getNomMatiere() {
return this.nomMatiere;
}
public void setNomMatiere(String nomMatiere) {
this.nomMatiere = nomMatiere;
}
@Column(name = "coefficient", nullable = false)
public int getCoefficient() {
return this.coefficient;
}
public void setCoefficient(int coefficient) {
this.coefficient = coefficient;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "matiere")
public Set<ProfMat> getProfMats() {
return this.profMats;
}
public void setProfMats(Set<ProfMat> profMats) {
this.profMats = profMats;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "matiere")
public Set<Module> getModules() {
return this.modules;
}
public void setModules(Set<Module> modules) {
this.modules = modules;
}
}
答案 1 :(得分:0)
其中一个类ProfMat
或Module
未映射到Hibernate。应通过配置定义映射。如果您正在使用注释配置,则在关联的类上放置@Table
注释,并确保扫描类以进行注释。