対応によって移入されませんCampaignEntity.class
エンティティです:複合キーは、ここでID
@Entity
@Table(name = "campaign_country")
@IdClass(CampaignCountry.CampaignCountryPK.class)
public class CampaignCountry {
@Id
@Column(name="campaign_id")
private Long campaignId;
@Id
@Column(name="country")
private String country;
public CampaignCountry(String country) {
this.country = country;
}
//getters and setters
static class CampaignCountryPK implements Serializable {
private Long campaignId;
private String country;
public CampaignCountryPK() {}
public CampaignCountryPK(Long campaignId, String country) {
this.campaignId = campaignId;
this.country = country;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CampaignCountryPK that = (CampaignCountryPK) o;
if (campaignId != null ? !campaignId.equals(that.campaignId) : that.campaignId != null) return false;
return country != null ? country.equals(that.country) : that.country == null;
}
@Override
public int hashCode() {
int result = campaignId != null ? campaignId.hashCode() : 0;
result = 31 * result + (country != null ? country.hashCode() : 0);
return result;
}
}
}
私は「とき、問題が来る:
@Entity
@Table(name = "campaign")
public class CampaignEntity implements Serializable {
@Id
@SequenceGenerator(name = "campaign_id_gen", sequenceName = "campaign_seq", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "campaign_id_gen")
private Long id;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "campaignId", fetch = FetchType.EAGER, targetEntity = CampaignCountry.class)
private List<CampaignCountry> countries;
@Column(name = "include_countries")
private Boolean includeCountries;
// getters & setters, toString, hashEquals
}
そして、ここでは、私がマップしようとしているCampaignCountry.class
ですm repository.saveAndFlush(campaignEntity)
を呼び出します。必要に応じて国を保存しますが、CampaignIdは保存しません。それは常にnullです。
org.springframework.orm.jpa.JpaObjectRetrievalFailureException:ID domain.CampaignCountry$CampaignCountryPK[email protected]でdomain.CampaignCountryを見つけることができません。ここでは、ID [email protected]
でdomain.CampaignCountryを見つけることができません(それは何も関係している場合)、移行SQLスクリプトです:
ネストされた例外はjavax.persistence.EntityNotFoundExceptionです。
ここで何が間違っているのですか。campaignIdに対応するcampaignEntityのIDを設定するにはどうすればよいですか? @OneToManyアノテーションには何かがあると思いますが、正しく実装されていない可能性があります。
'@OneToMany(cascade = CascadeType.ALL、mappedBy =" campaignId "、fetch = FetchType.EAGER、targetEntity = CampaignCountry.class)' – juvenislux
エンティティクラスが奇妙に見えます。 – Frank
@juvenislux助けてくれなかった。まだヌルです。 – Amiko