我正在使用springboot,使用单个表进行继承,我在使用add函数时遇到问题,如何自动插入discriminator列值, ps:我不使用entityManager。 谢谢 :) 这是3个实体和添加功能的代码
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="Type_res",
discriminatorType=DiscriminatorType.STRING, length=4)
public abstract class Reservation implements Serializable {....}
@Entity
@DiscriminatorValue("TRAIN")
public class Training extends Reservation{ ... }
@Entity @DiscriminatorValue("MEET")
public class Meeting extends Reservation{ ... }
@PostMapping("/reservations/training/{spaceId}/{userId}")
public Training addTraining(@PathVariable Long spaceId, @PathVariable(value = "userId") Long userId, @Valid @RequestBody Training training)
{
User user = userRepository.findById(userId) .orElseThrow(() -> new ResourceNotFoundException("User", "id", userId));
return spaceRepository.findById(spaceId) .map(space -> {
training.setSpace(space);
training.setCourse (training.getCourse());
training.setStatus(training.getStatus());
training.setResponsable(training.getResponsable());
training.setEnd_date(training.getEnd_date());
training.setStart_date(training.getStart_date());
training.setUser(user);
return trainingRepository.save(training); }
)
.orElseThrow(() -> new ResourceNotFoundException("Space", "id " ,spaceId)); }