我正在尝试将我的数据库与 Entity 类映射,但我不明白为什么会出现此异常。这是我的课:
@Entity
@Table(name = "process")
public class GeneralProcess implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "processid")
private Long ProcessId;
@Column(name = "processname")
private String Name;
// @Transient
// private GeneralProcess Analog;
// @Transient
// private Topic ProjectTopic;
// @Transient
// private String OperatorComment;
// //@Column(name = "substrate")
// @Transient
// private Substrates Substrate;
// @Transient
// private List <GeneralLayer> Structure = new
//ArrayList<GeneralLayer>();
// @Transient
// private List <ProcessError> Errors= new ArrayList<ProcessError>
//();
// @Transient
// private String EmptyString= "
//";
// @Transient
// private StringBuffer st= new StringBuffer();
public GeneralProcess() {}
public String getName() {return Name;}
public void setName (String s) {Name=s;}
public Long getProcessId() {return ProcessId;}
public void setProcessId (Long s) {ProcessId=s;}
// public void setAnalog(GeneralProcess analog) {
// Analog = analog;
// }
// public void setProjectTopic (Topic s) {ProjectTopic=s;}
// public void setOperatorComment (String s) {OperatorComment=s;}
// public void setSubstrate (Substrates s) {Substrate=s;}
// public void setStructure (List<GeneralLayer> l) {Structure=l;}
// public void setErrors (List<ProcessError> l) {Errors=l;}
// public GeneralProcess getAnalog() {
// return Analog;
// }
//
// public Topic getProjectTopic() { return ProjectTopic; }
// public String getOperatorComment() {
// return OperatorComment;
// }
// public Substrates getSubstrate() {
// return Substrate;
// }
// public List<GeneralLayer> getStructure() {
// return Structure;
// }
// public List<ProcessError> getErrors() {
// return Errors;
// }
//some other methods...
}
我的主要方法:
public static void main(String[] args) {
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
.configure( "hibernate.cfg.xml" )
.build();
Metadata metadata = new MetadataSources( standardRegistry )
.addAnnotatedClass( GeneralProcess.class )
.getMetadataBuilder()
.build();
SessionFactory sessionFactory = metadata.buildSessionFactory();
Session s = sessionFactory.openSession();
s.beginTransaction();
List<GeneralProcess> processList = s.createQuery("from GeneralProcess").list();
processList.stream().forEach((n)-> System.out.println(n.getName()));
s.getTransaction().commit();
s.close();
StandardServiceRegistryBuilder.destroy(standardRegistry);
}
}
所以我有以下异常:线程“main”中的异常org.hibernate.MappingException:无法确定类型:ProcessPackage.Process,在表:进程,列:[org.hibernate.mapping.Column(Analog)]为什么Hibernate 尝试映射 Analog 字段,虽然它被评论了?感谢您的任何帮助!