weixin_42378803
2010-07-04 21:49 浏览 180
已采纳

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条回答 默认 最新

  • 已采纳
    MasterKingZZN MasterKingZZN 2010-07-07 18:48

    你的ejb3-persistence.jar呢?

    点赞 评论 复制链接分享

相关推荐