您的位置:首页 > 其它

hibernate4.3Hello 第一个程序遇到的坑 【给自己的总结】

2017-03-02 12:49 573 查看
看着官方文档一步一步来,环境就是搭不起来了,折腾了半天,看着网上的的入门教程是没有问题的,最后发现是使用的了hibernate4 hibernate.cfg.xml文件红色标记的部分   
<?xml version ='1.0'encoding ='utf-8'?>

< hibernate-configuration
        xmlns = “http://www.hibernate.org/xsd/hibernate-configuration”
        xsi:schemaLocation = “http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd”
        xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” >
  < session-factory >
    <! - 数据库连接设置 - >
    < property name = “connection.driver_class” > org.hsqldb.jdbcDriver </ property > 
    < property name = “connection.url” > jdbc:hsqldb:hsql:// localhost </ property > 
    < property name = “connection.username” > sa </ property > 
    < property name = “connection.password” > </ property > 

    <! -  JDBC连接池(使用内置) - >
    < property name = “connection.pool_size” > 1 </ property > 

    <! -  SQL方言 - >
    < property name = “dialect” > org.hibernate.dialect.HSQLDialect </ property > 

    <! - 启用Hibernate的自动会话上下文管理 - >
    < property name = “current_session_context_class” > thread </ property > 

    <! - 禁用二级缓存 - >
    < property name = “cache.provider_class” > org.hibernate.cache.internal.NoCacheProvider </ property > 

    <! - 回显所有执行的SQL到stdout  - >
    < property name = “show_sql” > true </ property > 

    <! - 在启动时删除并重新创建数据库模式 - >
    < property name = “hbm2ddl.auto” > update </ property > 
    < mapping resource = “org / hibernate / tutorial / domain / Event.hbm.xml” /> 
  </ session-factory >
</ hibernate-configuration >
把红色部分换成 黑色部分 ,程序终于可以正常运行
<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>        <property name="connection.url">jdbc:mysql://127.0.0.1:3306/hibernate4?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true</property>        <property name="connection.username">root</property>        <property name="connection.password">1234</property>        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>               <property name="current_session_context_class">thread</property>        <property name="show_sql">true</property>        <property name="hbm2ddl.auto">update</property>     <!--    <mapping class="com.hibernate4.beans.User" /> -->        <mapping resource="com/hibernate4/beans/user.hbm.xml"/>    </session-factory></hibernate-configuration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: