【问题标题】:in spring jpa : can i use define class as @Embeddable and still use it as bean?在 spring jpa 中:我可以将定义类用作@Embeddable 并仍然将其用作 bean 吗?
【发布时间】:2013-04-28 20:33:41
【问题描述】:

我有一个关于 Spring beans 和 JPA 的问题

我有一个实体 A 它具有 Embeddable 类 B 作为参数之一。 B 将 Embeddable 类 C 作为其参数之一。

我的问题是:我可以将 C 用作可嵌入类和 spring bean 吗?例如。我可以做类似的事情吗

@RequestMapping(value = "game/nextQuestion/answer/{userAnswer}", method = RequestMethod.POST)
@ResponseBody
public final Question answer(
        @PathVariable("userAnswer") final Long userAnswer,
        @RequestBody final QuestionDetails details,
        @ModelAttribute("game") GameObject game, Model m)
        throws GameNotFoundException {

    return model.answer(userAnswer, game, m,details);
}

在上面的示例中,QuestionDetails 是嵌入在“B”中的“C”类,它嵌入在“A”中 问题是“A”类

谢谢!

橡木

【问题讨论】:

    标签: spring spring-data-jpa


    【解决方案1】:

    简单地说,是的,你可以。这是普通的 POJO 类。特殊用法仅在此类被持久化时使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 2020-10-17
      • 2017-03-08
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多