设置-Oracle 12.1.0.2、Kotlin、Hibernate
我有这样创建的表:
create or replace type capacity_varray as varray (4000) of int;
create table plan_capacities
(
id int generated by default as identity not null constraint plan_capacities_pkey primary key,
line_id int references lines (id) on delete cascade,
model_id int references models (id) on delete cascade,
plan_id int references plans (id) on delete cascade,
capacity capacity_varray
);
此表的模型:
@Entity()
@Table(name = "plan_capacities")
@TypeDefs(
TypeDef(name = "int-array", typeClass = IntArrayType::class)
)
data class PlanCapacity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int,
@ManyToOne
@JoinColumn(name = "line_Id")
val line: Line,
@ManyToOne()
@JoinColumn(name = "model_Id")
val model: Model,
@JsonBackReference
@ManyToOne()
@JoinColumn(name = "plan_id")
val plan: Plan,
@Column(name = "capacity")
@Type(type = "int-array")
val capacity: IntArray
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as PlanCapacity
if (id != other.id) return false
if (line != other.line) return false
if (model != other.model) return false
if (plan != other.plan) return false
if (!Arrays.equals(capacity, other.capacity)) return false
return true
}
override fun hashCode(): Int {
var result = id
result = 31 * result + line.hashCode()
result = 31 * result + model.hashCode()
result = 31 * result + plan.hashCode()
result = 31 * result + Arrays.hashCode(capacity)
return result
}
}
从数据库中错误地转换了数组,我得到
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
所以我尝试实现我自己的转换器实现
UserType
但在这里,我坚持将数组设置为db。
正确的处理方法是什么
int
阵列?我应该如何为这个特定的表和类型编写模型?
我想要
IntArray
从那个领域。