学习hibernate的首日写了个小程序就出现了bug,找了点资料还是很快给解决了
刚开始的时候是:
package cn.edu.njupt.zzq.hibernatestudy.domain.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import cn.edu.njupt.zzq.hibernatestudy.domain.Student;
public class StudentTest {
/**
* @param args
*/
public static void main(String[] args) {
Student s=new Student();
s.setId(2);
s.setName("强强");
s.setAge(20);
Configuration cgf=new Configuration();
/////////////////////////////////
SessionFactory sf=cgf.buildSessionFactory();
/////////////////////////////////////////
Session session=sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();
}
}
红色的地方出错了,应该写成,加上蓝色的方法
SessionFactory sf=cgf.configure().buildSessionFactory();
这样就行了啊!
但是上面这个方法已经过时了
下面给个不过时的:
public static void main(String[] args) {
Student s=new Student();
s.setId(3);
s.setName("强强");
s.setAge(20);
Configuration cgf=new Configuration();
//SessionFactory sf=cgf.configure().buildSessionFactory();
cgf.configure();//不要缺少或写在下面,这个是configure和serviceregistry之间
ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(cgf.getProperties()).buildServiceRegistry();
SessionFactory sf = cgf.buildSessionFactory(sr);
Session session=sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();
相关推荐
hibernate.dialect org.hibernate.dialect.HSQLDialect hibernate.connection.driver_class org.hsqldb.jdbcDriver hibernate.connection.username sa hibernate.connection.password hibernate.connection.url jdbc...
1.1、将两个jar包:com.zy.hibernate.dialect.SQLiteDialect.jar、sqlite-jdbc-3.7.2.jar拷贝到“\WEB-INF\lib”文件夹下; 2、配置hibernate: 2.1、将“hibernate\hibernate.cfg.xml”拷贝到“\WEB-INF\classes”...
亲测可以使用kingbase8-Finaldialect-5.2.17.jar kingbase8-8.2.0.jar
hibernate3.6.0dialect.jar
oracle连接字符串: class:oracle.jdbc.driver.OracleDriver url:"jdbc:oracle:thin:@localhost:1521:jbitdb","epet","epet" sqlserver: ...url:"jdbc:sqlserver:/...Firebird org.hibernate.dialect.FirebirdDialect
hibernate.dialect = org.hibernate.dialect.MySQLDialect //指定数据库使用的sql方言(oracle、mysql) hibernate.connection.driver_class=com.mysql.jdbc.Driver //指定数据库的驱动程序 hibernate.connection....
SQLServer2008Dialect 优化了原来的分页查询数据方法以及在生成SQL时表后增加了with(nolock)
hibernate.dialect=org.hibernate.dialect.SQLServerDialect hibernate.connection.driver_class=com.microsoft.sqlserver.jdbc.SQLServerDriver hibernate.connection.url=jdbc\:sqlserver\://localhost\:1433;...
南大通用GBase数据库GBase_Hibernate3.2.3_GA-Dialect_8.3.81.51_build50.1.jar
hibernate3dialect
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect <prop key="hibernate.show_sql">false !-- Create/update the database tables automatically when the JVM starts up <prop key="...
Hibernate人大金仓jar包
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory 3.3配置如下: <property name="hibernate.cache.use_second_level_cache">true <property name="cache...
hibernate下的kingbase的jar文件,需要的同学自行下载
#hibernate.dialect org.hibernate.dialect.MySQLDialect #hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect #hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect #hibernate.connection....
1.Caused by: org.hibernate.HibernateException: Connection cannot be null when ‘hibernate.dialect’ not set 报错就配置吧 启动项目不报错了,但是访问项目报错了 2.访问报错...
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect <!-- 可选配置 --> <property name="hibernate.show_sql">true <property name="hibernate.format_sql">true ...
hibernate.dialect=net.sf.hibernate.dialect.OracleDialect 如果是Oracle9,写 hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect 注意社区提供的是For Oracle8.1.7的JDBC驱动,如果使用Oracle9,需要...
org.hibernate.dialect.MySQLDialect <value>vo/Users.hbm.xml <value>vo/Firstdate.hbm.xml <value>vo/Arrangement.hbm.xml</value></list> </property>
hibernate5.2.0源码