日期:2014-05-17  浏览次数:20770 次

Initial SessionFactory creation failedorg.hibernate.AnnotationException:
刚写的报错:
Initial SessionFactory creation failedorg.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.super120.Model.Operation.oper in com.super120.Model.Operation.operations
用的hibernate3.6.10
hibernateUtils类
public class HibernateUtils {

private static final SessionFactory sessionFactory;

static {
try {
Configuration cfg = new Configuration();
sessionFactory = cfg.configure().buildSessionFactory();
} catch (Throwable e) {
System.err.println("Initial SessionFactory creation failed" + e);
throw new ExceptionInInitializerError(e);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

public static Session getSession() {
return sessionFactory.openSession();
}

public static void closeSession(Session session) throws HibernateException {
if (session != null) {
if (session.isOpen()) {
session.close();
}
}
}

public static void rollback(Transaction tran) {
try {
if (tran != null) {
tran.rollback();
}
} catch (HibernateException he) {
System.out.println("Rollback faild." + he);
}
}
}



operation类:

package com.super120.Model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="tb_Operation")
public class Operation {
private int ID;

private String OperationName;

private String Description;

private String Reserved;

private Set<Operation> operations = new HashSet<Operation>();



@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}



@OneToMany(cascade={CascadeType.REMOVE},fetch=FetchType.EAGER,mappedBy="oper")
public Set<Operation> getOperations() {
return operations;
}

public void setOperations(Set<Operation> operations) {
this.operations = operations;
}


public String getOperationName() {
return OperationName;
}

public void setOperationName(String operationName) {
OperationName&