异常:java.lang.NoClassDefFoundError:无法初始化类com.db.DatabaseOperations

时间:2018-08-08 05:27:49

标签: hibernate jsf

这是我的汽车课

import com.db.DatabaseOperations;

@ManagedBean @ViewScoped
public class Car implements java.io.Serializable {


private int cid;
private String cname;
private String color;
private String speed;
private List<Car> carFind;
private List<Car> carsList;
private boolean show;
public static DatabaseOperations dbObj;
private static final long serialVersionUID = 1L;

这是DatabaseOperations类

import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;

import org.hibernate.Query;
import org.hibernate.Session; 
import org.hibernate.Transaction;

import com.car.model.Car;
import com.util.HibernateUtil;

public class DatabaseOperations {

private static Transaction transObj;
private static Session sessionObj = HibernateUtil.getSessionFactory().openSession();

// Method To Add New Student Details In Database
public void addCarInDb(Car carObj) {        
    try {
        transObj = sessionObj.beginTransaction();
        sessionObj.save(carObj);
        System.out.println("Student Record With Id: " + carObj.getCid() + " Is Successfully Created In Database");

        // XHTML Response Text
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("createdCarId",  carObj.getCid());                       
    } catch (Exception exceptionObj) {
        exceptionObj.printStackTrace();
    } finally {
        transObj.commit();
    }
}

0 个答案:

没有答案