Hibernate 3.5中对annotation集成后在配置方面有什么变化么?

hibernate 3.5

写了个简单的测试程序

 

eclipse没提示有如何错误


运行后无如何结果  数据库也没有插入数据

 

控制台无提示 直接就是terminated

 


 

 

package annotation.model;

import javax.persistence.*;

@Entity
public class Teacher {

    private int id;
    private String name;
    private String title;
    
    @Id
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
}

 

 

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import annotation.model.Teacher;

public class TeacherTest {

    public static void main(String[] args) {
        Teacher t = new Teacher();  
        t.setId(1);
        t.setName("asdf");
        t.setTitle("a");    
        Configuration cfg = new AnnotationConfiguration();
        SessionFactory sf = cfg.configure().buildSessionFactory();
        Session session = sf.openSession();
        session.beginTransaction();
        session.save(t);
        session.close();
        sf.close();
    }
}

1个回答

你的ejb3-persistence.jar呢?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问