我有一个带有TINYINT(3)作为主键的MySQL表。根据我的理解(以及通过hibernate'validate'设置的内容),字节类型映射到TINYINT。一切都编译好,将检索所有数据。但是,当我去创建一个新条目时,我收到了这个错误:
org.springframework.orm.jpa.JpaSystemException: unrecognized id type : byte -> java.lang.Byte; nested exception is org.hibernate.id.IdentifierGenerationException: unrecognized id type : byte -> java.lang.Byte] with root cause
我在@GeneratedValue(strategy = GenerationType.AUTO)
字段上使用了注释@Id
。有没有办法让这项工作?
感谢。
以下是整个班级:
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="unittypes",schema="utilities")
public class UnitType implements Serializable {
private static final long serialVersionUID = 1L;
private byte unitTypeID;
private String unitTypeName;
public UnitType() {}
public UnitType(String unitTypeName) {
this.unitTypeName = unitTypeName;
}
@Id
@Column(name="pk_unittypeid")
@GeneratedValue(strategy = GenerationType.AUTO)
public byte getUnitTypeID() {
return unitTypeID;
}
public void setUnitTypeID(byte unitTypeID) {
this.unitTypeID = unitTypeID;
}
@Column(name="unittypename", unique=true, nullable=false)
public String getUnitTypeName() {
return unitTypeName;
}
public void setUnitTypeName(String unitTypeName) {
this.unitTypeName = unitTypeName;
}
@Override
public int hashCode() {
int hash = 7;
hash = 41 * hash + Objects.hashCode(this.unitTypeName);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final UnitType other = (UnitType) obj;
if (!Objects.equals(this.unitTypeName, other.unitTypeName)) {
return false;
}
return true;
}
}