真有你的!
1.在配置文件hibernate.cfg.xml中:
<hibernate-configuration>
<session-factory>
<!--URL-->
<property name="hibernate.connection.url">
jdbc:jtds:sqlserver://localhost:1433/dbname
</property>
<!--Driver-->
<property name="hibernate.connection.driver_class">
net.sourceforge.jtds.jdbc.Driver
</property>
<!--username-->
<property name="hibernate.connection.username">
sa
</property>
<!--password-->
<property name="hibernate.connection.password">
password
</property>
<!--dialect-->
<property name="hibernate.connection.dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>
<!--mapping file-->
<mapping resource="org/hibernate/sample/tablename.hbm.xml"/>
2.在程序中:
Configuration config=new Configuration().configure();
SessionFactory sessionFactory=config.buildSessionFactory();
session=sessionFactory.openSession();
Transaction action = session.beginTransaction();
tablename tb=new tablename();
tb.setAttri("77");
action.commit();
session.save(tb);
}catch(Exception e){
System.out.println(e.toString());
}
1.在配置文件hibernate.cfg.xml中:
<hibernate-configuration>
<session-factory>
<!--URL-->
<property name="hibernate.connection.url">
jdbc:jtds:sqlserver://localhost:1433/dbname
</property>
<!--Driver-->
<property name="hibernate.connection.driver_class">
net.sourceforge.jtds.jdbc.Driver
</property>
<!--username-->
<property name="hibernate.connection.username">
sa
</property>
<!--password-->
<property name="hibernate.connection.password">
password
</property>
<!--dialect-->
<property name="hibernate.connection.dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>
<!--mapping file-->
<mapping resource="org/hibernate/sample/tablename.hbm.xml"/>
2.在程序中:
Configuration config=new Configuration().configure();
SessionFactory sessionFactory=config.buildSessionFactory();
session=sessionFactory.openSession();
Transaction action = session.beginTransaction();
tablename tb=new tablename();
tb.setAttri("77");
action.commit();
session.save(tb);
}catch(Exception e){
System.out.println(e.toString());
}
我运行后,出现以下错误:
WARN SettingsFactory:103 - Could not obtain connection metadata
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:371)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:188)
......
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
......这是什么问题?要如何解决???
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect
我记得是这样配置的
<property name="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<propertyname="hibernate.connection.dialect">org.hibernate.dialect.SQLServerDialect
</property>因为这个hibernate包的这个路径就是org.hibernate.dialect.SQLServerDialect而不是
net.sf.hibernate.dialect.SQLServerDialect到底还有什么地方错了??错误不是:org.hibernate.HibernateException: Hibernate Dialect must be explicitly set at org.hibernate.dialect.DialectFactory.determineDialect再请大家帮帮忙吧!!
<property name="hibernate.dialect">
你的是这样
<propertyname="hibernate.connection.dialect">
看出区别了吗?
property 与 name 之间是有空格的.
里面的字符串也不一样, 你按我的试试
WARN SettingsFactory:103 - Could not obtain connection metadata
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:371)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
......
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
....
Caused by: java.sql.SQLException: Network error IOException: Connection refused: connect
....
Caused by: java.net.ConnectException: Connection refused: connect
到底哪里有错?还请各位帮忙!
ERROR BasicLazyInitializer:104 - CGLIB Enhancement failed: hibernate3.Customer
java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:95)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
....
WARN PojoEntityTuplizer:167 - could not create proxy factory for:hibernate3.Customer
org.hibernate.HibernateException: CGLIB Enhancement failed: hibernate3.Customer
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:106)
.....
aused by: java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:95)
请各位指导!
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.getNameParser(InitialContext.java:429)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:293)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1091)
at hibernate3.test2.main(test2.java:17)
是什么错误??
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration><session-factory>
<property name="myeclipse.connection.profile">test</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://计算机名字:1433;DataBaseName=数据库名
</property>
<property name="connection.username">数据用户名</property>
<property name="connection.password">密码</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property></session-factory></hibernate-configuration>
拷贝,填写一下,就ok~~
<!-- properties -->
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Hibernate_Struts_Test</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.timeout">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
</session-factory>这样试试