集成休眠时运行时错误

时间:2016-08-09 15:05:44

标签: hibernate

我现在正在研究这几天。按照简单的youtube教程我试图设置我的休眠。以下是我创建的所有类,但是我已经检查了我的运行时配置,它们有驱动程序,构建路径也是如此。我不明白缺少什么,请尽快帮助!

的hibernate.cfg.xml          

    <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/nebuladb</property>
    <property name="hibernate.connection.username">****</property>
    <property name="hibernate.connection.password">****</property>
    <property name="hibernate.connection.driver_class">org.postgresql.driver</property>
    <property name="hibernate.connection.pool_size">1</property>
    <property name="hibernate.connection.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">create</property>
    <mapping class="careers.nebula.ben.db.enitity.signup.UserEntity"/>
</session-factory>

实体:

@Entity
public class UserEntity {
@Id
private int id;
private String firstName;
private String lastName;
private String preferredName;
private String phoneNumber;
private String email;
private String photoUrl;
private String videoUrl;
private String personalWebsiteUrl;
private String fbUrl;
private String linkedinUrl;
private String goals;
private String aboutMe;
private Boolean currentlyEmployeed;
private Boolean currentlyInSchool;
private String highestQualification;
private int rating;

public int getId() {
    return id;
}
public void setId(int 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;
}
public String getPreferredName() {
    return preferredName;
}
public void setPreferredName(String preferredName) {
    this.preferredName = preferredName;
}
public String getPhoneNumber() {
    return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
    this.phoneNumber = phoneNumber;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public String getPhotoUrl() {
    return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
    this.photoUrl = photoUrl;
}
public String getVideoUrl() {
    return videoUrl;
}
public void setVideoUrl(String videoUrl) {
    this.videoUrl = videoUrl;
}
public String getPersonalWebsiteUrl() {
    return personalWebsiteUrl;
}
public void setPersonalWebsiteUrl(String personalWebsiteUrl) {
    this.personalWebsiteUrl = personalWebsiteUrl;
}
public String getGoals() {
    return goals;
}
public void setGoals(String goals) {
    this.goals = goals;
}
public String getAboutMe() {
    return aboutMe;
}
public void setAboutMe(String aboutMe) {
    this.aboutMe = aboutMe;
}
public Boolean getCurrentlyEmployeed() {
    return currentlyEmployeed;
}
public void setCurrentlyEmployeed(Boolean currentlyEmployeed) {
    this.currentlyEmployeed = currentlyEmployeed;
}
public Boolean getCurrentlyInSchool() {
    return currentlyInSchool;
}
public void setCurrentlyInSchool(Boolean currentlyInSchool) {
    this.currentlyInSchool = currentlyInSchool;
}
public String getHighestQualification() {
    return highestQualification;
}
public void setHighestQualification(String highestQualification) {
    this.highestQualification = highestQualification;
}
public int getRating() {
    return rating;
}
public void setRating(int rating) {
    this.rating = rating;
}
public String getFbUrl() {
    return fbUrl;
}
public void setFbUrl(String fbUrl) {
    this.fbUrl = fbUrl;
}
public String getLinkedinUrl() {
    return linkedinUrl;
}
public void setLinkedinUrl(String linkedinUrl) {
    this.linkedinUrl = linkedinUrl;
}
}

服务:

public class UserInformation {


public static void main(String[] args){
    UserEntity userEntity = new UserEntity();
    userEntity.setFirstName("Ankit");
    userEntity.setLastName("Verma");
    userEntity.setPreferredName("ankibunkers");
    userEntity.setPhoneNumber("9097172039");
    userEntity.setEmail("ankitv@uci.edu");
    userEntity.setCurrentlyInSchool(false);
    userEntity.setCurrentlyEmployeed(true);
    userEntity.setGoals("earn my masters in computer science from harvard");
    userEntity.setAboutMe("passionate young attractive stud");
    userEntity.setPhotoUrl("www.photo.url.com");
    userEntity.setVideoUrl("www.video.url.com");
    userEntity.setFbUrl("www.fb.url.com");
    userEntity.setLinkedinUrl("www.linkedin.url.com");
    userEntity.setRating(4);

    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    session.save(userEntity);
    session.getTransaction().commit();
}
}

1 个答案:

答案 0 :(得分:0)

驱动程序url postgresql.driver需要是postgresql.Driver。哎呀!