【发布时间】:2011-06-28 01:56:45
【问题描述】:
我正在开发一个使用 Hibernate 和 MySQL 的项目。在我的一个模型对象中,我声明了一个类型为 Blob 的属性“图像”,并且我使用了 com.mysql.jdbc.Blob。但是当我运行该程序时,发生错误:org.hibernate.MappingException:无法确定类型:com.mysql.jdbc.Blob,表:SPOT,列:[org.hibernate.mapping.Column(image) ]。 这是数据模型的源代码:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "SPOT", catalog = "ar", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
@XmlRootElement(name = "spot")
public class Spot extends BaseIdObject {
private Double axisX;
private Double axisY;
private String address;
private String spotType;
private String description;
private String phoneNumber;
private String website;
private Blob image;
@Column(name = "axis_x", precision = 22, scale = 0)
@NotNull
public Double getAxisX() {
return this.axisX;
}
public void setAxisX(Double axisX) {
this.axisX = axisX;
}
@Column(name = "axis_y", precision = 22, scale = 0)
@NotNull
public Double getAxisY() {
return this.axisY;
}
public void setAxisY(Double axisY) {
this.axisY = axisY;
}
@Column(name = "address", length = 200)
@NotNull
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
@Column(name = "spot_type", length = 50)
@NotNull
public String getSpotType() {
return this.spotType;
}
public void setSpotType(String spotType) {
this.spotType = spotType;
}
@Column(name = "description", length = 2000)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@Column(name = "phone_number", length = 30)
public String getPhoneNumber() {
return this.phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
这里是表SPOT对应的DDL:
DROP TABLE IF EXISTS `spot`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `spot` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) DEFAULT NULL,
`AXIS_X` double NOT NULL,
`AXIS_Y` double NOT NULL,
`ADDRESS` varchar(200) DEFAULT NULL,
`SPOT_TYPE` varchar(50) NOT NULL,
`DESCRIPTION` varchar(2000) DEFAULT NULL,
`PHONE_NUMBER` varchar(30) DEFAULT NULL,
`WEBSITE` varchar(200) DEFAULT NULL,
`IMAGE` blob,
PRIMARY KEY (`ID`),
UNIQUE KEY `SPOT_ID_UNIQUE` (`ID`),
UNIQUE KEY `SPOT_NAME_UNIQUE` (`NAME`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
我在互联网上搜索,发现使用 java.sql.Blob 的建议。但是当我改成那个类型时,又出现了一个错误,因为在我的程序中,我在那个模型对象上用XML做了一些处理,所以它不能处理接口java.sql.Blob。那么我必须做些什么来保持数据类型 com.mysql.jdbc.Blob 并且程序仍然可以在 Hibernate 中正常运行?非常感谢。
【问题讨论】:
标签: mysql hibernate hibernate-mapping