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


看着官方文档一步一步来,环境就是搭不起来了,折腾了半天,看着网上的的入门教程

是没有问题的,

最后发现是使用的了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&amp;characterEncoding=UTF-8&amp;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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值