EclipseLink ADD CONSTRAINT异常

时间:2016-01-11 12:33:45

标签: java sql-server jpa eclipselink

我想使用create-or-extend-tables,但eclipselink在创建表后会给出以下错误。我使用的是Eclipselink 2.5.2,db是MS Sql 2014

  

异常[EclipseLink-4002](Eclipse持久性服务 -   2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.DatabaseException内部   例外:com.microsoft.sqlserver.jdbc.SQLServerException:   'announcementCOMPANY_ID'对象已存在。错误代码:2714致电:   ALTER TABLE公告ADD CONSTRAINT announcementCOMPANY_ID FOREIGN   KEY(COMPANY_ID)REFERENCES公司(ID)查询:   DataModifyQuery(sql =“ALTER TABLE announcement ADD CONSTRAINT   announcementCOMPANY_ID FOREIGN KEY(COMPANY_ID)参考公司   (ID)“)

Persistance.java

<uses-permission>

Announcement.java

@Entity @table(名称= “公告”) 公共课公告{

persistenceMap.put("javax.persistence.jdbc.driver", ConfigParams
                       .getInstance().getValue(ConfigConstants.JDBC_DRIVER));
         persistenceMap.put("javax.persistence.jdbc.user", ConfigParams
                       .getInstance().getValue(ConfigConstants.JDBC_USER));
         persistenceMap.put("javax.persistence.jdbc.password", ConfigParams
                       .getInstance().getValue(ConfigConstants.JDBC_PASSWORD));
         persistenceMap.put("javax.persistence.jdbc.url", ConfigParams
                       .getInstance().getValue(ConfigConstants.JDBC_URL));

         persistenceMap.put("eclipselink.logging.logger",
                       Log4jSessionLog.class.getName());
         // persistenceMap.put("eclipselink.logging.file",
         // Log4jSessionLog.class.getName());

         persistenceMap
                       .put("eclipselink.ddl-generation.output-mode", "database");
         persistenceMap.put("eclipselink.weaving.internal", "false");
         persistenceMap.put("eclipselink.logging.level", ConfigParams
                       .getInstance().getValue(ConfigConstants.JDBC_LOGGING_LEVEL));
         persistenceMap.put("eclipselink.ddl-generation",
                       "create-or-extend-tables");

}

Company.java

@Entity @Table(名称= “公司”) 公共级公司{

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "annId")
        private int id;

        @Column(nullable =false, length = 250, name="annName")
        private String name;

        @Column(length = 250)
        private String mainTitle;

        @Column(nullable=false, length = 250)
        private String subTitle;

        @Lob
        private String content;

        @Column(nullable = false)
        private Date startDate;

        @Transient
        private java.util.Date startDateUtil;

        @Column(nullable = false)
        private Date endDate;

        @Transient
        private java.util.Date endDateUtil;

        @Lob
        private String imgUrl;

        @Column(nullable = false)
        private boolean isActive;

        @Column(nullable = false)
        private boolean isDeleted;

        @Transient
        private BtcResponse status;


        private Type type;

        @ManyToMany
        @JoinTable(name="announcementLogs")
        private List<Log> logAList = new ArrayList<Log>();


        private Company company;

        public int getId() {
                    return id;
        }

        public void setId(int id) {
                    this.id = id;
        }

        public String getName() {
                    return name;
        }

        public void setName(String name) {
                    this.name = name;
        }

        public String getMainTitle() {
                    return mainTitle;
        }

        public void setMainTitle(String mainTitle) {
                    this.mainTitle = mainTitle;
        }

        public String getSubTitle() {
                    return subTitle;
        }

        public void setSubTitle(String subTitle) {
                    this.subTitle = subTitle;
        }

        public String getContent() {
                    return content;
        }

        public void setContent(String content) {
                    this.content = content;
        }

        public Date getStartDate() {
                    return startDate;
        }

        public void setStartDate(Date startDate) {
                    this.startDate = startDate;
        }

        public java.util.Date getStartDateUtil() {
                    return startDateUtil;
        }

        public void setStartDateUtil(java.util.Date startDateUtil) {
                    this.startDateUtil = startDateUtil;
        }

        public Date getEndDate() {
                    return endDate;
        }

        public void setEndDate(Date endDate) {
                    this.endDate = endDate;
        }

        public java.util.Date getEndDateUtil() {
                    return endDateUtil;
        }

        public void setEndDateUtil(java.util.Date endDateUtil) {
                    this.endDateUtil = endDateUtil;
        }

        public String getImgUrl() {
                    return imgUrl;
        }

        public void setImgUrl(String imgUrl) {
                    this.imgUrl = imgUrl;
        }

        public boolean isActive() {
                    return isActive;
        }

        public void setActive(boolean isActive) {
                    this.isActive = isActive;
        }

        public boolean isDeleted() {
                    return isDeleted;
        }

        public void setDeleted(boolean isDeleted) {
                    this.isDeleted = isDeleted;
        }

        public BtcResponse getStatus() {
                    return status;
        }

        public void setStatus(BtcResponse status) {
                    this.status = status;
        }

        public List<Log> getLogAList() {
                    return logAList;
        }

        public void setLogAList(List<Log> logAList) {
                    this.logAList = logAList;
        }

        @ManyToOne
        public Type getType() {
                    return type;
        }

        public void setType(Type type) {
                    this.type = type;
        }

        public Announcement() {
                    super();
        }

        public Announcement(BtcResponse status) {
                    super();
                    this.status = status;
        }

        public Announcement(java.util.Date startDateUtil,
                               java.util.Date endDateUtil, String imgUrl, boolean isActive) {
                    super();
                    this.startDateUtil = startDateUtil;
                    this.endDateUtil = endDateUtil;
                    this.imgUrl = imgUrl;
                    this.isActive = isActive;
        }

        @ManyToOne
        @JoinColumn(name = "id")
        public Company getCompany() {
                    return company;
        }
        public void setCompany(Company company) {
                    this.company = company;
        }           

}

0 个答案:

没有答案