无法实例化抽象类或接口:持久化时出现问题

时间:2010-06-05 15:44:19

标签: hibernate hibernate-annotations

我有一个维护AdGroupInterfaces列表的课程广告系列。即将继续实施

    @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的实施是AdGroups。当我在广告系列的列表中添加广告组时,

广告系列c; c.getAdGroupList()。add(new AdGroups())等 和 保存广告系列

它说“无法实例化抽象类或接口:”AdGroupInterface

它在持续存在之前没有认识到实施......

而持久化广告组分开运作。当它是另一个实体的成员时,它不会被持久化。

         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;
}

}

我错过了什么?请调查一下......

1 个答案:

答案 0 :(得分:2)

我认为targetEntity关联的OneToMany应该是一个类(可能是抽象的,但不是接口)。看看this previous answer