线程“Thread-10”中出现异常。数据访问应用程序使用无效异常:实体[in.happysellers.hdb.gold.orders.DummyTable]中属性[产品]的类型[类java.util.可选]未知;只允许基元类型和基元类型的集合或Map
我已经手动插入值在cassandra表,并尝试通过查询获取,它是给我正确的记录,那么为什么我不能保存记录通过代码使用optional.我认为应该有一些注解使用可选值在repo文件,我无法找到.
package in.happysellers.hdb.gold.orders
import in.happysellers.utils.DateTimeUtils
import org.hibernate.annotations.Type
import org.springframework.data.cassandra.core.cql.PrimaryKeyType
import org.springframework.data.cassandra.core.mapping.{Column, PrimaryKeyColumn, Table}
import org.springframework.lang.Nullable
import java.sql.Timestamp
import java.util.Optional
import javax.persistence._
@Table("dummy_table")
class DummyTable private {
@Id
@PrimaryKeyColumn(name = "user_id", `type` = PrimaryKeyType.PARTITIONED)
var userId: Long = _
@Column("product")
@Nullable
var product: Optional[String] = _
@Column("product_details")
@Nullable
var productDetails: Optional[String] = _
@Column("quantity")
var quantity: Int = _
@Column("cost")
var cost: Float = _
@PrimaryKeyColumn(name = "created_at", `type` = PrimaryKeyType.CLUSTERED)
var createdAt: Timestamp = _
def this(userId: Long, product: Optional[String],productDetails: Optional[String], quantity: Int, cost: Float) {
this()
this.userId = userId
this.product = product
this.productDetails = productDetails
this.quantity = quantity
this.cost = cost
this.createdAt = DateTimeUtils.currentTimestamp
}
}
1条答案
按热度按时间q3qa4bjr1#
错误消息指示列
product
中的值的类型不匹配;这是因为传递的是可选变量,而不是字符串。这样,如果没有提供产品,将分配默认的
NA
(或您定义的任何字符串)。