org.hibernate.AnnotationException:从<parentclass>引用<childclass>的外键具有错误的第3列数

时间:2018-08-07 16:29:47

标签: java spring hibernate persistence jpa-2.0

我正在尝试使用@ManyToOne映射设置Java JPA。下面是我的课程。

DAO类:

public List<CMSClientDTO> getAllClients(Long clientId) {
    clDTO= new CMSClientDTO();

    EntityManager em= emf.createEntityManager();
    final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<CMSClientDTO> criteriaQuery = criteriaBuilder.createQuery(CMSClientDTO.class);
    Root<CMSClientDTO> root = criteriaQuery.from(CMSClientDTO.class);
     criteriaQuery.select(root).where(criteriaBuilder.or(criteriaBuilder.equal(root.get("clientId"), clientId),
            criteriaBuilder.equal(root.get("clientParentId"), clientId)));
     Query query=em.createQuery(criteriaQuery);
    List<CMSClientDTO> cmsClients  = query.getResultList();

    for(CMSClientDTO clientDTO : cmsClients){
        clientIds.add(clientDTO.getClientId());
    return cmsClients;

}

CMSCLIENTDTO:

@Entity
@Table(name="cms_client", schema="CMS_APP")

public class CMSClientDTO implements Serializable {


    @Column(name="CLIENT_ID", nullable=false)
    @Id
    private Long clientId;

    @Id
    @ManyToOne
    //@ManyToOne(targetEntity = ClientContactDTO.class)
    @JoinColumn(name="CLIENT_ID", insertable=false, updatable=false)
    private ClientContactDTO clientContact;

    public ClientContactDTO getClientContact() {
        return clientContact;
    }

    public void setClientContact(ClientContactDTO clientContact) {
        this.clientContact = clientContact;
    }


    public Long getClientId() {
        return clientId;
    }


    public void setClientId(Long clientId) {
        this.clientId = clientId;
    }

@Entity
@Table(name="CMS_CLIENT_CONTACT",schema="CMS_APP")
@SequenceGenerator(name = "CMS_CLIENT_ID_SEQ", sequenceName = "CMS_APP.CMS_CLIENT_ID_SEQ", allocationSize = 1 )

public class ClientContactDTO implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 5711843524571402195L;

    public ClientContactDTO() {
        super();
    }

    public ClientContactDTO(Long clientIdContact, Long contactId, String contactRole, String contactTypeCd, Date effectiveDate,
            long supercededInd, Date createDate, String createUser, Date updateDate, String updateUser,
            Integer deleteInd, String comments, String legacyContactType, Integer aosContactUpdate,
            Integer isLegacyToOther, Integer displayNotifications) {
        super();
        this.clientIdContact = clientIdContact;
        this.contactId = contactId;
        this.contactRole = contactRole;
        this.contactTypeCd = contactTypeCd;
        this.effectiveDate = effectiveDate;
        this.supercededInd = supercededInd;
        this.createDate = createDate;
        this.createUser = createUser;
        this.updateDate = updateDate;
        this.updateUser = updateUser;
        this.deleteInd = deleteInd;
        this.comments = comments;
        this.legacyContactType = legacyContactType;
        this.aosContactUpdate = aosContactUpdate;
        this.isLegacyToOther = isLegacyToOther;
        this.displayNotifications = displayNotifications;
    }


    @Id
    @Column(name="CLIENT_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CMS_CLIENT_ID_SEQ")
    private Long clientIdContact;


    public Long getClientIdContact() {
        return clientIdContact;
    }

    public void setClientIdContact(Long clientIdContact) {
        this.clientIdContact = clientIdContact;
    }

    @Id
    @Column(name="CONTACT_ID")
    private Long contactId;

    @Id
    @ManyToOne
    @JoinColumn(name="CONTACT_ID",insertable=false,nullable=false)
    private ContactDTO contact;


    /**
     * @return the contact
     */
    public ContactDTO getContact() {
        return contact;
    }

    /**
     * @param contact the contact to set
     */
    public void setContact(ContactDTO contact) {
        this.contact = contact;
    }

ContactDTO:

@Entity
@Table(name = "CMS_CONTACT", schema = "CMS_APP" )
@SequenceGenerator(name = "CMS_CONTACT_ID_SEQ", sequenceName = "CMS_APP.CMS_CONTACT_ID_SEQ", allocationSize = 1 )
public class ContactDTO {

    public ContactDTO() {
        super();
    }

    public ContactDTO(String contactFaxArea, String contactFaxExch,
            String contactFaxNum, String contactCellArea,
            String contactCellExch, String contactCellNum,
            String contactFirstNM, String contactLastNM, String contactMI,
            String contactPhoneArea, String contactPhoneExch,
            String contactPhoneNum, String contactPhoneExt,
            String contactBusEmail, String contactPrsnlEmail,
            String primaryContact, String benefitsAdmin,
            String contactHomePhoneArea, String contactHomePhoneExch,
            String contactHomePhoneNum, String contactOtherPhoneArea,
            String contactOtherPhoneExch, String contactOtherPhoneNum,
            String contactOtherPhoneExt, String cpaName) {
        super();
        this.contactFaxArea = contactFaxArea;
        this.contactFaxExch = contactFaxExch;
        this.contactFaxNum = contactFaxNum;
        this.contactCellArea = contactCellArea;
        this.contactCellExch = contactCellExch;
        this.contactCellNum = contactCellNum;
        this.contactFirstNM = contactFirstNM;
        this.contactLastNM = contactLastNM;
        this.contactMI = contactMI;
        this.contactPhoneArea = contactPhoneArea;
        this.contactPhoneExch = contactPhoneExch;
        this.contactPhoneNum = contactPhoneNum;
        this.contactPhoneExt = contactPhoneExt;
        this.contactBusEmail = contactBusEmail;
        this.contactPrsnlEmail = contactPrsnlEmail;
        this.primaryContact = primaryContact;
        this.benefitsAdmin = benefitsAdmin;
        this.contactHomePhoneArea = contactHomePhoneArea;
        this.contactHomePhoneExch = contactHomePhoneExch;
        this.contactHomePhoneNum = contactHomePhoneNum;
        this.contactOtherPhoneArea = contactOtherPhoneArea;
        this.contactOtherPhoneExch = contactOtherPhoneExch;
        this.contactOtherPhoneNum = contactOtherPhoneNum;
        this.contactOtherPhoneExt = contactOtherPhoneExt;
        // this.createDate = createDate;
        // this.createUser = createUser;
        this.cpaName = cpaName;
    }

    @Column(name = "CONTACT_ID")
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CMS_CONTACT_ID_SEQ")
    private Long contactId;

我遇到了错误:

  

org.springframework.beans.factory.BeanCreationException:创建在ServletContext资源[/WEB-INF/spring/ISExtenalAppContext.xml]中定义的名称为'emf'的bean时出错:调用init方法失败;嵌套异常是org.hibernate.AnnotationException:从com.adp.is.dto.CMSClientDTO引用com.adp.is.dto.ClientContactDTO的外键具有错误的列数。应该是3

我是Spring和JPA的新手。

0 个答案:

没有答案