Я использую отношения javax.persistence.onetomany в родительских отношениях. The parent Id is coming as null, I have read through all the related post in Stackoverflow but not getting any clue what I am missing.
All the Corresponding PKs are getting populated in both Parent & Child tables as per the Sequence Provided, but the FK is set to null in Child table
Parent Class:
@Entity
@Table(name = "DIVERSITY_TEMPLATE")
public class DiversityTemplate implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "DIVERSITY_TEMPLATE_ID", sequenceName = "DIVERSITY_TEMPLATE_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DIVERSITY_TEMPLATE_ID")
@Column(name = "DIVERSITY_TEMPLATE_ID")
private Integer diversityTemplateId;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "diversityTemplate", fetch = FetchType.LAZY)
private List attributes = new ArrayList();
< /code>
chlals: < /strong> < /p>
@Entity
@Table(name = "DIVERSITY_TEMPLATE_ATTRIBUTE")
@TypeName("DiversityTemplateAttribute")
public class DiversityTemplateAttribute implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "DIVERSITY_TEMPLATE_ATTR_ID", sequenceName = "DIVERSITY_TEMPLATE_ATTR_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DIVERSITY_TEMPLATE_ATTR_ID")
@Column(name = "DIVERSITY_TEMPLATE_ATTR_ID")
private Integer diversityTemplateAttributeId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DIVERSITY_TEMPLATE_ID", nullable=false, referencedColumnName = "DIVERSITY_TEMPLATE_ID")
private DiversityTemplate diversityTemplate;
< /code>
класс службы: < /strong> < /p>
diversityTemplateRepository.save(diversityTemplate);
< /code>
Образец json < /strong> < /p>
{
"diversityTemplateId": 0,
"attributes": [{
"diversityTemplateId": 0,
"diversityTemplateAttributeId": 0,
}, {
"diversityTemplateId": 0,
"diversityTemplateAttributeId": 0,
}]
}
< /code>
Пожалуйста, предложите. < /p>
Подробнее здесь: https://stackoverflow.com/questions/433 ... apping-jpa
Родительский идентификатор NULL в @onetomany Mapping JPA ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение