初学hibernate遇到的问题

1.hibernate Connection cannot be null when 'hibernate.dialect' not set

public class Test {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Teacher t = new Teacher();
  //student.setId(1);
  t.setId(4);
  t.setName("cc");
  t.setTitle("高级");
  Configuration cg = new Configuration();
  cg.configure();//不要缺少或写在下面,这个是configure和serviceregistry之间
  ServiceRegistry  sr = new ServiceRegistryBuilder().applySettings(cg.getProperties()).buildServiceRegistry(); 
  SessionFactory sf = cg.buildSessionFactory(sr);
  Session s = sf.openSession();
  s.beginTransaction();
  s.save(t);
  s.getTransaction().commit();
  s.close();
  sf.close();
 }

}

http://www.cnblogs.com/slowly-keeping/archive/2012/04/18/2455293.html

2.org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MYSQL5Dialect

MySql版本问题导致的Hibernate 方言问题 (2012-06-26 10:09:11)
标签: 杂谈 分类: Hibernate
Mysql 版本 5.0以前的Hibernate 方言是:
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
 
Mysql 版本 5.0以后的Hibernate 方言是:
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
参考:http://blog.163.com/tianshenglongchang@126/blog/static/1646285032013018113536478/

3. could not instantiate id generator

<generator class="native"> </generator> 
或 indentity

因为我的的主键是自动增长的. 
increment 生成策略 是hibernate 生成一个值 然后插到你的mysql数据库. 所以报错

http://bbs.csdn.net/topics/230057963

 

posted @ 2015-04-08 10:16  smallsunshine  阅读(98)  评论(0)    收藏  举报