oracle 阵列,Oracle阵列和休眠

设置-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

从那个领域。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值