システムで複合パターンを実装して使用しようとしています。複合パターン、バックエンドからすべてのエンティティを取得できません
問題は、バックエンドからエンティティのすべての階層を取得できないということです。
私は問題が何であるか分かりませんが、フェッチは問題ありません。だから、私は休止状態であるかどうかはわかりません。
これは自分のエンティティです。私はメインの "GameRule" このクラスで
@Entity
@Table(name = "game_rule")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("rule")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "_class")
@JsonSubTypes({
@JsonSubTypes.Type(value = SimpleRule.class, name = "SimpleRule"),
@JsonSubTypes.Type(value = CompositeRule.class, name = "CompositeRule") })
public abstract class GameRule implements Serializable {
private static final long serialVersionUID = -4597791997254248990L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
private String operator;
を保存し、このクラスで
@Entity
@Table(name = "game")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "game")
public class Game extends AbstractAuditingEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
@Column(name = "name", nullable = false)
private String name;
@Column(name = "detail")
private String detail;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "rule_id")
private GameRule gameRule;
...
私はGameRules
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("group")
public class CompositeRule extends GameRule {
private static final long serialVersionUID = 6197786758476721324L;
@ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
@JoinTable(name = "game_rules_hierarchy",
joinColumns = @JoinColumn(name = "parent_rule_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "child_rule_id", referencedColumnName = "id"))
@OrderBy("id")
private List<GameRule> rules;
public List<GameRule> getRules() { return rules; }
public void setRules(List<GameRule> rules) { this.rules = rules; }
そして今、葉のエンティティのリストを保存します。
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("simple")
public class SimpleRule extends GameRule {
private static final long serialVersionUID = 6197786758476721324L;
private String variable;
private Double value;
@ManyToOne
@NotNull
private Device device;
さて、restControllerは私がsimpleRuleオブジェクトに関するCompositeRuleオブジェクトだけを受信することができる午前ビューで今すぐデータ
@RequestMapping(value = "/games/{id}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@Transactional
public ResponseEntity<Game> getGame(@PathVariable Long id) {
log.debug("REST request to get Game : {}", id);
Game game = gameRepository.findOne(id);
return Optional.ofNullable(game)
.map(result -> new ResponseEntity<>(
result,
HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
を取得します。
UI(角)から、このJSONを使用して階層をロードしています。
vm.game.gameRule = {id: null, operator: "", type:null, _class:"CompositeRule",
rules: [ {id: null, operator: "", type:null, _class:"CompositeRule", rules:
[{id: null, type:null, _class:"SimpleRule", device: "6", variable: "POWER", operator: ">", value: "100"},
{id: null, type:null, _class:"SimpleRule", device: "6", variable: "POWER", operator: ">", value: "100"}]}
]};
これは、DBに正常に読み込まれます。しかし、問題は、私が階層全体を取得しようとするときです。現在、私はCompositeRuleオブジェクトしか受けていません。
vm.game.gameRule = {id: 1, operator: "", type:null, _class:"CompositeRule",
rules: [ {id: 2, operator: "", type:null, _class:"CompositeRule", rules:[]} ]};]
RestControllerではすべての階層オブジェクトを見ることができます。私は問題が何であるか分かりません。
読んでいただきありがとうございます。