首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Hibernate Dialect must be explicitly set

2011-12-26 
Hibernate 可编程配问题?100分ConfigurationcfgnewConfiguration().addFile( CcCifNgtvInfo.hbm.xml )

Hibernate 可编程配问题?100分

                        Configuration   cfg   =   new   Configuration()
                        .addFile( "CcCifNgtvInfo.hbm.xml ");
                        SessionFactory   sessions   =   cfg.buildSessionFactory();//到这里抛出异常
                        Session   sess   =   sessions.openSession(conn);//程序已有的连接

输出信息:
2007-9-7   17:06:00   org.hibernate.cfg.Environment
INFO:   Hibernate   3.2.5
2007-9-7   17:06:03   org.hibernate.cfg.Environment
INFO:   hibernate.properties   not   found
2007-9-7   17:06:03   org.hibernate.cfg.Environment
INFO:   Bytecode   provider   name   :   cglib
2007-9-7   17:06:04   org.hibernate.cfg.Environment
INFO:   using   JDK   1.4   java.sql.Timestamp   handling
2007-9-7   17:06:05   org.hibernate.cfg.Configuration
INFO:   Reading   mappings   from   file:   CcCifNgtvInfo.hbm.xml
2007-9-7   17:06:09   org.hibernate.cfg.HbmBinder
INFO:   Mapping   class:   core.cc.cif.entity.CcCifNgtvInfo   ->   CC_CIF_NGTV_INFO
2007-9-7   17:06:11   org.hibernate.mapping.RootClass
WARNING:   composite-id   class   does   not   override   equals():   core.cc.cif.entity.CcCifNgtvInfo
2007-9-7   17:06:11   org.hibernate.mapping.RootClass
WARNING:   composite-id   class   does   not   override   hashCode():   core.cc.cif.entity.CcCifNgtvInfo
2007-9-7   17:06:11   org.hibernate.connection.UserSuppliedConnectionProvider
WARNING:   No   connection   properties   specified   -   the   user   must   supply   JDBC   connections
Exception   in   thread   "main "   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)
at   org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426)
at   org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
at   org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at   core.cc.cif.batch.HibernateTestJob.saveNgtvData(HibernateTestJob.java:129)
at   core.cc.cif.batch.HibernateTestJob.execute(HibernateTestJob.java:69)
at   core.cc.cif.batch.HibernateTestJob.main(HibernateTestJob.java:312)


[解决办法]
Hibernate Dialect must be explicitly set
就是说你hibernate方言没设正确 检查你的hibernate.cfg.xml
<?xml version= "1.0 " encoding= "utf-8 "?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN "
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">

<hibernate-configuration>
<session-factory>
<!-- datasource connection properties -->
<property name= "connection.datasource ">
java:comp/env/jdbc/arts
</property>



<!-- dialect for Mysql (InnoDB) -->
<property name= "dialect ">
org.hibernate.dialect.MySQLInnoDBDialect
</property>
<property name= "hibernate.show_sql "> false </property>
<property name= "hibernate.transaction.factory_class ">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- mapping files -->
<property name= "jndi.url "> jdbc:mysql://localhost/arts </property>
<mapping resource= "Smallclass.hbm.xml " />
</session-factory>
</hibernate-configuration>

这里给你举一个例子 注意 <property name= "dialect ">
org.hibernate.dialect.MySQLInnoDBDialect
</property>

[解决办法]
up
[解决办法]
CcCifNgtvInfo.hbm.xml文件需要路径
File file = new File( "c:\\CcCifNgtvInfo.hbm.xml ");
Configuration config = new Configuration.configure(file);
[解决办法]
可能是你的hibernate.properties文件中没有设置dialect
[解决办法]
也有楼上面说的dialect 我是从错误提示上看的
[解决办法]
应该加载你的hibernate配置文件吧,你怎么加载的是映射文件呢,
[解决办法]
顶一个
[解决办法]
不懂,
up
[解决办法]
这样加载映射文件肯定是不行的.Configuration cfg = new Configuration()本身就是设置加载配置文件的,而你的映射文件里没有任何于配置相关的项.
hibernate是通过配置文件来设置session,然后通过session根据映射文件去操作数据库.你这么做根本就是反过来了.通过映射文件去设置session,然后session再反过来操作映射文件,这样这么可能对呢.
总之,hibernate不是你这么用地
[解决办法]
你的问题应该不是太大,从打印来看,可能是配置有问题,具体情况要你自己看了,
按照freedom2001(天翔) 说得,你在仔细看看,把原理弄懂就好了,
[解决办法]
配置文件的问题,检查hibernate.cfg.xml、xxx.hbm.xml等文件
在程序中直接这样写就ok了,SessionFactory sf = new Configuration().buildSessionFactory();
[解决办法]
如果不想用hibernate,而直接采用jdbc方式连接数据库的话,那需要你自己写获得数据库连接的代码

[解决办法]
不管你的连接是哪里的,您得给一个方言的配置,配置的属性文件是得有的啊

热点排行