Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
hibernate加入子类重复键_Hibernate_Joined Subclass - Fatal编程技术网

hibernate加入子类重复键

hibernate加入子类重复键,hibernate,joined-subclass,Hibernate,Joined Subclass,谢谢你的好奇,我需要你的帮助:) 因此,我创建了一个联合继承:父类称为“Action”,子类称为“AwardAction”和“LevelUpAction”。我用hibernate注释和3个表创建了3个类。它工作了好几个月,但最近出现了一个问题 问题是我们发现了两个具有相同id的条目“LevelUpAction”和“AwardAction”,它们与“Action”中的一个条目相关 [操作id=502] /\ /\ [AwardAction id=502][LevelUpAction id=502]

谢谢你的好奇,我需要你的帮助:)

因此,我创建了一个联合继承:父类称为“Action”,子类称为“AwardAction”和“LevelUpAction”。我用hibernate注释和3个表创建了3个类。它工作了好几个月,但最近出现了一个问题

问题是我们发现了两个具有相同id的条目“LevelUpAction”和“AwardAction”,它们与“Action”中的一个条目相关
[操作id=502]
/\
/\
[AwardAction id=502][LevelUpAction id=502]

这种情况不应该发生。每个levelUpAction和AwardAction都应该有自己的id

我们检查了代码,但没有发现任何问题。实际上,在这种情况下不应创建任何AwardAction。我们认为已经创建了一个LevelUpAction条目(如预期的那样),hibernate(出于未知原因)也创建了一个AwardAction条目

事实上,我想听听你对表格和课程的看法

课程:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Action extends AbstractKeyEntity {

@Column
@NotEmpty
private String userKey;

@Column
@NotNull
private int points = 0;

protected Action() {
}

protected Action(String userKey, int points) {
    super();
    this.userKey = userKey;
    this.points = points;
}

public int getPoints() {
    return points;
}

public String getUserKey(){
    return userKey;
}
}


表:

CREATE TABLE `level_up_action` (
`fast` tinyint(1) NOT NULL,
`fast_duration` bigint(20) DEFAULT NULL,
`rich` tinyint(1) NOT NULL,
`rich_points` bigint(20) DEFAULT NULL,
`id` bigint(20) NOT NULL,
`achievement_level_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_achievement_level_up_action_achievement_level` (`achievement_level_id`),
KEY `FK_achievement_level_up_action_to_achievement_action` (`id`),
CONSTRAINT `fk_achievement_level_up_action_achievement_level` FOREIGN KEY     (`achievement_level_id`) REFERENCES `achievement_level` (`id`),
CONSTRAINT `FK_achievement_level_up_action_to_action` FOREIGN KEY (`id`)     REFERENCES `action` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


@Entity
public class LevelUpAction extends Action {

@ForeignKey(name = "fk_achievement_level_up_action_achievement_level")
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "achievement_level_id")
@NotNull
private AchievementLevel achievementLevel;

@Column(columnDefinition = "BIT", length = 1)
@NotNull
private boolean fast = false;

@Column(columnDefinition = "BIT", length = 1)
@NotNull
private boolean rich = false;

@Column
private Long fastDuration = 0L;

@Column
private Long richPoints = 0L;

public LevelUpAction() {

}

public LevelUpAction(String userKey, int points, AchievementLevel achievementLevel) {
    super(userKey, points);
    this.achievementLevel = achievementLevel;
}

public boolean isFast() {
    return fast;
}

public void setFast(boolean fast) {
    this.fast = fast;
}

public boolean isRich() {
    return rich;
}

public void setRich(boolean rich) {
    this.rich = rich;
}

public Long getFastDuration() {
    return fastDuration;
}

public void setFastDuration(Long fastDuration) {
    this.fastDuration = fastDuration;
}

public Long getRichPoints() {
    return richPoints;
}

public void setRichPoints(Long richPoints) {
    this.richPoints = richPoints;
}

}
CREATE TABLE `level_up_action` (
`fast` tinyint(1) NOT NULL,
`fast_duration` bigint(20) DEFAULT NULL,
`rich` tinyint(1) NOT NULL,
`rich_points` bigint(20) DEFAULT NULL,
`id` bigint(20) NOT NULL,
`achievement_level_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_achievement_level_up_action_achievement_level` (`achievement_level_id`),
KEY `FK_achievement_level_up_action_to_achievement_action` (`id`),
CONSTRAINT `fk_achievement_level_up_action_achievement_level` FOREIGN KEY     (`achievement_level_id`) REFERENCES `achievement_level` (`id`),
CONSTRAINT `FK_achievement_level_up_action_to_action` FOREIGN KEY (`id`)     REFERENCES `action` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `action` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `created_at` datetime NOT NULL,
  `created_by` varchar(255) NOT NULL,
  `entity_key` varchar(255) NOT NULL,
  `modified_at` datetime NOT NULL,
  `modified_by` varchar(255) NOT NULL,
  `rs_deleted` bit(1) NOT NULL,
  `version` int(11) NOT NULL,
  `points` int(11) NOT NULL,
  `user_key` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UK_action_entity_key` (`entity_key`)
) ENGINE=InnoDB AUTO_INCREMENT=507 DEFAULT CHARSET=utf8;
CREATE TABLE `award_action` (
  `id` bigint(20) NOT NULL,
  `badge_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_award_action_to_badge` (`badge_id`),
  KEY `FK_award_action_to_achievement_action` (`id`),
  CONSTRAINT `fk_award_action_to_badge` FOREIGN KEY (`badge_id`) REFERENCES `badge` (`id`),
  CONSTRAINT `FK_award_action_to_action` FOREIGN KEY (`id`)         REFERENCES `action` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;