【问题标题】:Table not created when @EmbeddedId has an extra String property@EmbeddedId 具有额外的 String 属性时未创建表
【发布时间】:2021-08-23 02:56:17
【问题描述】:

我正在尝试为以下实体自动生成表格:

@Entity
@Table(name = "gas_price")
class GasPrice(
  @EmbeddedId
  var id: GasPriceId,
  var price: Double,
)

@Embeddable
class GasPriceId(
  @ManyToOne(optional = false)
  var gasStation: GasStation,
  var isSelf: Boolean,
  var readDate: Instant,
  var description: String
) : Serializable

事实上,该表不是在应用程序启动时生成的,但如果我删除

var description: String

表格确实生成了正确的值。

我不知道为什么会发生这种情况,有人遇到过类似的问题吗?

【问题讨论】:

  • 有错误提示吗?
  • 不,完全没有错误信息

标签: spring-boot hibernate kotlin jpa


【解决方案1】:

显然,在 @Embeddable 的 String 属性中,我必须定义列长度。所以:

@Column(length = 200)
var description: String

然后表格就生成了。我必须调查原因,但这解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 2018-04-16
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多