@OneToOne annotation with optional = true generates an exception when value is null
-----------------------------------------------------------------------------------
Key: HHH-5847
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5847
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.6.0
Reporter: guy bashan
I am currently in the process of upgrading from Hibernate 3.3 to 3.6.
I didn't have the following problem before the upgrade.
I am getting the following exception when trying to persist an object:
-------------------------------------------------------------------------------------
Caused by: org.hibernate.PropertyValueException: not-null property references a null or
transient value: com.todacell.ui.model.bo.campaign.Campaign.targetDays
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:100)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:312)
at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:673)
at com.todacell.ui.model.dao.BaseDAO.saveObject(BaseDAO.java:82)
at com.todacell.ui.model.dao.CampaignDAO.saveObject(CampaignDAO.java:23)
at
com.todacell.ui.view.bean.campaign.CampaignGeneralInfoBean.saveAction(CampaignGeneralInfoBean.java:204)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
... 37 more
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Seems like there is a problem when I am trying to persist the object with: targetDays
empty (it should be empty at this point).
This is the bean I am using:
-----------------------------------
@Entity
@Table(name = "cmp_campaign")
public class Campaign implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "campaign_id")
private Integer campaignId;
@Column(name = "name")
@NotNull
@Length(max = 100)
private String name;
@Column(name = "creative_name")
@Length(max = 100)
private String creativeName;
@Column(name = "comments")
@Length(max = 4000)
private String comments;
@ManyToOne
@JoinColumn(name = "advertiser_id")
private Advertiser advertiser;
@ManyToOne
@JoinColumn(name = "agency_id")
private Agency agency;
@OneToMany(mappedBy = "campaign", cascade =
{javax.persistence.CascadeType.ALL})
@OrderBy("adId")
@Cascade({org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<Ad> ads;
@OneToOne(mappedBy = "campaign")
@JoinColumn(name = "campaign_id")
@Cascade({org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private DeliveryLimits deliveryLimits;
@OneToOne(mappedBy = "campaign")
@JoinColumn(name = "campaign_id")
@Cascade({org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Cost cost;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "cmp_target_list_option",
joinColumns = {@JoinColumn(name = "campaign_id")},
inverseJoinColumns = @JoinColumn(name = "option_id"))
private Set<ListTargetingParamOption> listTargetingParamOptions;
@OneToOne(optional = true)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@PrimaryKeyJoinColumn
private LastStatus lastStatus;
@OneToMany(mappedBy = "campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@Sort(type = SortType.COMPARATOR, comparator =
TargetKeyword.TargetKeywordComparator.class)
private SortedSet<TargetKeyword> targetKeywords;
@OneToMany(mappedBy = "campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetNumberRange> targetNumberRanges;
@OneToOne(fetch = FetchType.LAZY, optional = true)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@PrimaryKeyJoinColumn
private TargetDays targetDays;
@OneToMany(mappedBy = "campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@Sort(type = SortType.COMPARATOR, comparator =
TargetDayPart.TargetDayPartComparator.class)
private SortedSet<TargetDayPart> targetDayParts;
@OneToMany(mappedBy = "targetTesterPK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@Sort(type = SortType.COMPARATOR, comparator =
TargetTester.TargetTesterComparator.class)
private SortedSet<TargetTester> targetTesters;
@OneToMany(mappedBy = "targetLocationPK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetLocation> targetLocations;
@OneToMany(mappedBy = "targetCountryMobileOperatorPK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetOperator> targetOperators;
@OneToMany(mappedBy = "campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetSystem> targetSystems;
@OneToMany(mappedBy = "targetDevicePK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetDevice> targetDevices;
@OneToMany(mappedBy = "targetDeviceOsPK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetDeviceOs> targetDeviceOss;
@OneToMany(mappedBy = "targetIpPK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetIp> targetIps;
@OneToMany(mappedBy = "targetIpRangePK.campaign")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<TargetIpRange> targetIpRanges;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "cmp_target_publisher",
joinColumns = {@JoinColumn(name = "campaign_id")},
inverseJoinColumns = @JoinColumn(name = "publisher_id"))
@Sort(type = SortType.COMPARATOR, comparator = Publisher.PublisherComparator.class)
private SortedSet<Publisher> targetPublishers;
@Column(name = "source")
@Type(type = "com.todacell.ui.model.persistence.StringValuedEnumType",
parameters = @Parameter(name = "enum", value =
"com.todacell.ui.model.bo.system.CampaignSource"))
@NotNull
private CampaignSource source;
@ManyToOne
@JoinColumn(name = "third_party_id")
private ThirdPartyServer thirdPartyServer;
@ManyToOne
@JoinColumn(name = "order_id")
private Order order;
@Column(name = "time_zone")
@NotNull
@Length(max = 50)
private String timeZone;
@Column(name = "status_check_date")
private Date statusCheckDate;
@Column(name = "active")
private Boolean active;
@Column(name = "version_current_date")
private Date versionCurrentDate;
@Column(name = "version_deploy_date")
private Date versionDeployDate;
@Column(name = "category")
@Type(type = "com.todacell.ui.model.persistence.StringValuedEnumType",
parameters = @Parameter(name = "enum", value =
"com.todacell.ui.model.bo.system.CampaignCategory"))
@NotNull
private CampaignCategory category;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "cmp_target_site",
joinColumns = {@JoinColumn(name = "campaign_id")},
inverseJoinColumns = @JoinColumn(name = "site_id"))
@Sort(type = SortType.COMPARATOR, comparator = Site.SiteComparator.class)
private SortedSet<Site> targetSites;
public Campaign() {
}
public Integer getCampaignId() {
return campaignId;
}
public void setCampaignId(Integer campaignId) {
this.campaignId = campaignId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCreativeName() {
return creativeName;
}
public void setCreativeName(String creativeName) {
this.creativeName = creativeName;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public Advertiser getAdvertiser() {
return advertiser;
}
public void setAdvertiser(Advertiser pubAdvertiser) {
this.advertiser = pubAdvertiser;
}
public Agency getAgency() {
return agency;
}
public void setAgency(Agency agency) {
this.agency = agency;
}
public Set<Ad> getAds() {
return ads;
}
public void setAds(Set<Ad> ads) {
this.ads = ads;
}
public DeliveryLimits getDeliveryLimits() {
return deliveryLimits;
}
public void setDeliveryLimits(DeliveryLimits deliveryLimits) {
this.deliveryLimits = deliveryLimits;
}
public Cost getCost() {
return cost;
}
public void setCost(Cost cost) {
this.cost = cost;
}
public Double getPublisherCost()
{
return CampaignPerformanceUtil.getPublisherCost(cost);
}
public LastStatus getLastStatus() {
return lastStatus;
}
public void setLastStatus(LastStatus lastStatus) {
this.lastStatus = lastStatus;
}
public Set<TargetKeyword> getTargetKeywords() {
return targetKeywords;
}
public void setTargetKeywords(SortedSet<TargetKeyword> targetKeywords) {
this.targetKeywords = targetKeywords;
}
public Set<TargetNumberRange> getTargetNumberRanges() {
return targetNumberRanges;
}
public void setTargetNumberRanges(Set<TargetNumberRange> targetNumberRanges) {
this.targetNumberRanges = targetNumberRanges;
}
public TargetDays getTargetDays() {
return targetDays;
}
public void setTargetDays(TargetDays targetDays) {
this.targetDays = targetDays;
}
public Set<TargetDayPart> getCmpTargetDayParts() {
return targetDayParts;
}
public void setCmpTargetDayParts(SortedSet<TargetDayPart> targetDayParts) {
this.targetDayParts = targetDayParts;
}
public Set<TargetTester> getTargetTesters() {
return targetTesters;
}
public void setTargetTesters(SortedSet<TargetTester> targetTesters) {
this.targetTesters = targetTesters;
}
public Set<TargetLocation> getTargetLocations() {
return targetLocations;
}
public void setTargetLocations(Set<TargetLocation> targetLocations) {
this.targetLocations = targetLocations;
}
public Set<TargetDevice> getTargetMobileDevices() {
return targetDevices;
}
public void setTargetMobileDevices(Set<TargetDevice> targetDevices) {
this.targetDevices = targetDevices;
}
public Set<TargetOperator> getTargetCountryMobileOperators() {
return targetOperators;
}
public Set<TargetDeviceOs> getTargetDeviceOss() {
return targetDeviceOss;
}
public void setTargetDeviceOss(Set<TargetDeviceOs> targetDeviceOss) {
this.targetDeviceOss = targetDeviceOss;
}
public Set<TargetIp> getTargetIps() {
return targetIps;
}
public void setTargetIps(Set<TargetIp> targetIps) {
this.targetIps = targetIps;
}
public void setTargetCountryMobileOperators(Set<TargetOperator> targetOperators)
{
this.targetOperators = targetOperators;
}
public Set<TargetSystem> getTargetSystems() {
return targetSystems;
}
public void setTargetSystems(Set<TargetSystem> targetSystems) {
this.targetSystems = targetSystems;
}
public SortedSet<Publisher> getTargetPublishers() {
return targetPublishers;
}
public void setTargetPublishers(SortedSet<Publisher> targetPublishers) {
this.targetPublishers = targetPublishers;
}
public CampaignSource getSource() {
return source;
}
public void setSource(CampaignSource source) {
this.source = source;
}
public ThirdPartyServer getThirdPartyServer() {
return thirdPartyServer;
}
public void setThirdPartyServer(ThirdPartyServer thirdPartyServer) {
this.thirdPartyServer = thirdPartyServer;
}
public String getTimeZone() {
return timeZone;
}
public void setTimeZone(String timeZone) {
this.timeZone = timeZone;
}
public TimeZone getTimeZoneObj() {
return TimeZone.getTimeZone(timeZone);
}
public Date getStatusCheckDate() {
return statusCheckDate;
}
public void setStatusCheckDate(Date statusCheckDate) {
this.statusCheckDate = statusCheckDate;
}
public Boolean isActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public CampaignCategory getCategory() {
return category;
}
public void setCategory(CampaignCategory category) {
this.category = category;
}
public Date getVersionCurrentDate() {
return versionCurrentDate;
}
public void setVersionCurrentDate(Date versionCurrentDate) {
this.versionCurrentDate = versionCurrentDate;
}
public Date getVersionDeployDate() {
return versionDeployDate;
}
public void setVersionDeployDate(Date versionDeployDate) {
this.versionDeployDate = versionDeployDate;
}
public Set<ListTargetingParamOption> getListTargetingParamOptions() {
return listTargetingParamOptions;
}
public void setListTargetingParamOptions(Set<ListTargetingParamOption>
listTargetingParamOptions) {
this.listTargetingParamOptions = listTargetingParamOptions;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public List<Advertiser> getActiveAdvertisers(){
SysDAO dao = DAOFactory.getSysDAO();
return dao.getActiveAdvertisers();
}
public static class CampaignComparator implements Comparator<Campaign>,
Serializable
{
public int compare(Campaign campaign1, Campaign campaign2)
{
return campaign1.getName().compareTo(campaign2.getName());
}
}
public SortedSet<Site> getTargetSites() {
return targetSites;
}
public void setTargetSites(SortedSet<Site> targetSites) {
this.targetSites = targetSites;
}
public Set<TargetIpRange> getTargetIpRanges() {
return targetIpRanges;
}
public void setTargetIpRanges(Set<TargetIpRange> targetIpRanges) {
this.targetIpRanges = targetIpRanges;
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira