A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

这是我的Hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
       
<hibernate-configuration>
<!-- 先配置sessionFactory标签,一个数据库对应一个SessionFactory标签 -->
<session-factory>

<!-- 必须要配置的参数有5个,4大参数,数据库的方言 -->

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate_day01</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>

<!-- 数据库的方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 可选配置 -->
<!-- 显示sql语句,在控制台显示 -->
<property name="hibernate.show_sql">true</property>
<!-- 格式化sql语句 -->
<property name="hibernate.format_sql">true</property>
<!-- 生成表结构 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 映射配置文件 -->

<mapping resource="com/itheima/demain/Customer.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>

customer.htm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
   
   
<hibernate-mapping>
<!-- 配置类和表结构的映射 -->
<class name = "com.itheima.demain.Customer" table = "cst_customer">
<!-- 配置id
        见到name属性,javaBean的属性
        见到colun属性,是表结构的字段
-->
<id name = "cust_id" column="cust_id"></id>

<property name="cust_name" column = "cust_name"></property>
<property name="cust_user_i" column = "cust_user_i"></property>
<property name="cust_create_id" column = "cust_create_id"></property>
<property name="cust_source" column = "cust_source"></property>
<property name="cust_industry" column = "cust_industry"></property>
<property name="cust_level" column = "cust_level"></property>
<property name="cust_linkman" column = "cust_linkman"></property>
<property name="cust_phone" column = "cust_phone"></property>
<property name="cust_mobile" column = "cust_mobile"></property>
</class>
</hibernate-mapping>

测试程序之前没有错误,但是总提示有一个错误,感觉是配置文件的问题,大佬们可以帮忙看一下

2 个回复

倒序浏览
id没有生成自增策略
回复 使用道具 举报 1 0
1、customer.htm.xml和在核心配置中引入的映射表不一致,有个字母错误
2、没有id生成策略
3、建议你实体类的包启程domain(和错误没关系)
4、下次记得把控制台报错一起发出来。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马