i have a class campaign that maintains a list of AdGroupInterfaces. im going to persist its implementation
@Entity
@Table(name = "campaigns")
public class Campaign implements Serializable,Comparable<Object>,CampaignInterface {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany (
cascade = {CascadeType.ALL},
fetch = FetchType.EAGER,
targetEntity=AdGroupInterface.class
)
@org.hibernate.annotations.Cascade(
value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN
)
@org.hibernate.annotations.IndexColumn(name = "CHOICE_POSITION")
private List<AdGroupInterface> AdGroup;
public Campaign() {
super();
}
public List<AdGroupInterface> getAdGroup() {
return AdGroup;
}
public void setAdGroup(List<AdGroupInterface> adGroup) {
AdGroup = adGroup;
}
public void set1AdGroup(AdGroupInterface adGroup) {
if(AdGroup==null)
AdGroup=new LinkedList<AdGroupInterface>();
AdGroup.add(adGroup);
}
}
AdGroupInterface's implementation is AdGroups. when i add an adgroup to the list in campaign,
campaign c; c.getAdGroupList().add(new AdGroups()), etc and save campaign
it says"Cannot instantiate abstract class or interface :" AdGroupInterface
its not recognizing the implementation just before persisting...
Whereas Persisting adGroups separately works. when it is a member of another entity, it doesnt get persisted.
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
@Entity
@DiscriminatorValue("1")
@Table(name = "AdGroups")
public class AdGroups implements Serializable,Comparable,AdGroupInterface{
/**
*
*/
private static final long serialVersionUID = 1L;
private Long Id;
private String Name;
private CampaignInterface Campaign;
private MonetaryValue DefaultBid;
public AdGroups(){
super();
}
public AdGroups( String name, CampaignInterface campaign) {
super();
this.Campaign=new Campaign();
Name = name;
this.Campaign = campaign;
DefaultBid = defaultBid;
AdList=adList;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="AdGroup_Id")
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
@Column(name="AdGroup_Name")
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
@ManyToOne
@JoinColumn (name="Cam_ID", nullable = true,insertable = false)
public CampaignInterface getCampaign() {
return Campaign;
}
public void setCampaign(CampaignInterface campaign) {
this.Campaign = campaign;
}
}
what am i missing?? please look into it ...