无法转换为内部表示Spring数据JPA

时间:2016-09-21 12:03:04

标签: java hibernate enums spring-data spring-data-jpa

我正在使用Spring数据并尝试获取实体,但是无法加载其子元素,请参阅下面的代码:

using System.Windows.Forms;

namespace TryButtonToolTip
{
    public partial class TryToolTipForm : Form
    {
        public TryToolTipForm()
        {
            InitializeComponent();
            uC_TTMessage.TT_Message = @"Hi";
        }
    }
}

在存储库中

@Entity
@Table(name = "Pub")
public class Pub {

    private Integer id;
    private Date plannedDate;
    private Date startDate;
    private Date endDate;

    private Sub sub;

    private Date creationDate;
    private Date updateDate;

    private String log;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen")
    @SequenceGenerator(name = "gen", sequenceName = "sq_gen", allocationSize = 1)
    @Column(name = "ID", length = 19)
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "PLANNED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getPlannedDate() {
        return plannedDate;
    }
    public void setPlannedDate(Date plannedDate) {
        this.plannedDate = plannedDate;
    }

    @Column(name = "START_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getStartDate() {
        return startDate;
    }
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    @Column(name = "END_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getEndDate() {
        return endDate;
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }


    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "SUB_ID")
    public Sub getSub() {
        return sub;
    }
    public void setSub(Sub sub) {
        this.sub = sub;
    }

    @Column(name = "CREATION_DATE" , nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreationDate() {
        return creationDate;
    }
    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    @Column(name = "UPDATE_DATE", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getUpdateDate() {
        return updateDate;
    }
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @Basic(fetch=FetchType.LAZY)
    @Lob
    @Column(name = "LOG", nullable = false)
    public String getLog() {
        return log;
    }
    public void setLog(String log) {
        this.log = log;
    }

     public String toString() {
            return "" + id + " - " + status + " - " + subscription;
        }

}

我得到的例外是,在检索Sub(子实体)时失败了。我有从Pub到Sub(Many to One)的单向关系,这是否会导致以下错误?请建议

@Query("select p from Pub p where p.id=:pubId")
    public Publication getByPubIdId(@Param("pubId") Integer pubId);

感谢。

1 个答案:

答案 0 :(得分:0)

我已经解决了。在我的子实体中我有枚举,在其他类中提取后我能够获取记录。以前我的子实体是

private SubType isMailOrFtp;
enum SubType {
  SUB_MAIL, SUB_FTP   
}

我从中删除了枚举。

非常感谢