我的程序中有一个继承关系,因为Car和Van扩展了Vehicle。在我的情况下,这是强制性参与,因此如果存在车辆,则必须是汽车或货车。因此我只使用两个表(car& van),它们具有超类和子类字段的列。
public class Vehicle {
protected int vin;
protected String brand;
public Vehicle(){}
public Vehicle(int vin, String brand) {
this.vin = vin;
this.brand = brand;
}
public int getVin() {
return vin;
}
public void setVin(int vin) {
this.vin = vin;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
Car.java
public class Car extends Vehicle {
private String model;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public Car(){
}
public Car(int vin, String brand, String model) {
this.vin = vin;
this.brand = brand;
this.model = model;
}
Van.java
public class Van extends Vehicle {
private String vanModel;
public Van(){}
public Van(int vin,String brand,String vanModel) {
this.vanModel = vanModel;
this.vin=vin;
this.brand=brand;
}
public String getVanModel() {
return vanModel;
}
public void setVanModel(String vanModel) {
this.vanModel = vanModel;
}
映射文件
<?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>
<class name="Vehicle">
<id name="vin" type="int" column="vin">
<generator class="increment"/>
</id>
<property name="brand" column="brand"/>
<union-subclass name="Car" table="car">
<property name="model" column="model"/>
</union-subclass>
<union-subclass name="Van" table="van">
<property name="vanModel" column="vanmodel"/>
</union-subclass>
</class>
</hibernate-mapping>
当我尝试向汽车或货车表插入任何东西时,会出现以下错误。 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'myjdbc.vehicle'不存在。我不知道这个。我从未提过表名作为车辆。那我为什么会收到这个错误呢?由于我对冬眠很陌生,请给我一个详细的答案。