Initial SessionFactory creation failed.org.hibernate.HibernateException: Missing column: dept_id
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.atom.HibernateOne.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
at com.atom.HibernateOne.HibernateUtil.<clinit>(HibernateUtil.java:8)
at com.atom.HibernateOne.Main.main(Main.java:17)
Caused by: org.hibernate.HibernateException: Missing column: dept_id
at org.hibernate.mapping.Table.validateColumns(Table.java:212)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:964)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1164)
at com.atom.HibernateOne.HibernateUtil.buildSessionFactory(HibernateUtil.java:15)
部门表
CREATE TABLE `department` (
`dept_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`dept_name` VARCHAR(50) NOT NULL DEFAULT '0',
PRIMARY KEY (`dept_id`)
)
;
员工表
CREATE TABLE `employeeo` (
`employee_id` BIGINT(10) NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(50) NULL DEFAULT NULL,
`lastname` VARCHAR(50) NULL DEFAULT NULL,
`birth_date` DATE NULL DEFAULT NULL,
`cell_phone` VARCHAR(15) NULL DEFAULT NULL,
`deptest.departmentt_id` BIGINT(20) NULL DEFAULT NULL,
PRIMARY KEY (`employee_id`),
INDEX `FK_DEPT` (`dept_id`),
CONSTRAINT `FK_DEPT` FOREIGN KEY (`dept_id`) REFERENCES `department` (`dept_id`)
);
部门.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.atom.HibernateOne">
<class name="com.atom.HibernateOne.Department" table="department">
<id name="departmentId" type="java.lang.Long" column="dept_id" >
<generator class="identity" />
</id>
<property name="departmentName" column="DEPT_NAME"/>
<set name="employees"
table="EMPLOYEEO"
inverse="true"
fetch="select">
<key>
<column name="dept_id"
not-null="true" />
</key>
<one-to-many class="com.atom.HibernateOne.EmployeeO" />
</set>
</class>
</hibernate-mapping>
员工.hbm.xml
<class name="com.atom.HibernateOne.EmployeeO" table="EMPLOYEE">
<id name="employeeId" column="EMPLOYEE_ID">
</id>
<property name="firstname" column="FIRSTNAME"/>
<property name="lastname" column="LASTNAME" />
<property name="birthDate" type="date" column="BIRTH_DATE" />
<property name="cellphone" column="CELL_PHONE" />
<many-to-one name="department" class="com.atom.HibernateOne.Department" fetch="select">
<column name="dept_id" not-null="true" />
</many-to-one>
</class>
* 初始 SessionFactory 创建 failed.org.hibernate.HibernateException:缺少列:dept_id*
我无法理解错误的发生