0 Replies Latest reply on May 9, 2006 6:57 AM by taavi

    How to name foreign keys?

    taavi

      Hello everybody,

      I have a simple newby question. How can I name inside the ejb3 entity, the foreign key name.
      I have right now entys like this:

      import java.util.Date;
      
      import javax.persistence.Entity;
      import javax.persistence.ManyToOne;
      import javax.persistence.Table;
      import javax.persistence.Temporal;
      import javax.persistence.TemporalType;
      
      import ee.zero.mis.data.ABaseBean;
      import ee.zero.mis.data.IMisEntity;
      import ee.zero.mis.data.common.Person;
      import ee.zero.mis.data.common.Project;
      import ee.zero.mis.data.tm.classificators.WorkType;
      
      @Entity
      @Table(name = "Report")
      public class Report extends ABaseBean implements IMisEntity{
      
       private static final long serialVersionUID = 644015895309221489L;
      
       public final static String DATE = "reportDate";
       public final static String PERSON = "person";
       public final static String PROJECT = "project";
       public final static String DESCRIPTION = "description";
       public final static String TIME_COUNT = "timeCount";
       public final static String WORK_TYPE = "workType";
      
       private Date reportDate;
       @ManyToOne
       private Person person;
       @ManyToOne
       private Project project;
       private String description;
       private Long timeCount;
       @ManyToOne
       private WorkType workType;
      
      
      
       public WorkType getWorkType() {
       return workType;
       }
       public void setWorkType(WorkType workType) {
       this.workType = workType;
       }
       /**
       * @return Returns the description.
       */
       public String getDescription() {
       return description;
       }
       /**
       * @param description The description to set.
       */
       public void setDescription(String description) {
       this.description = description;
       }
       /**
       * @return Returns the person.
       */
       public Person getPerson() {
       return person;
       }
       /**
       * @param person The person to set.
       */
       public void setPerson(Person person) {
       this.person = person;
       }
       /**
       * @return Returns the project.
       */
       public Project getProject() {
       return project;
       }
       /**
       * @param project The project to set.
       */
       public void setProject(Project project) {
       this.project = project;
       }
       /**
       * @return Returns the timeCount.
       */
       public Long getTimeCount() {
       return timeCount;
       }
       /**
       * @param timeCount The timeCount to set.
       */
       public void setTimeCount(Long timeCount) {
       this.timeCount = timeCount;
       }
       @Temporal(TemporalType.DATE)
       public Date getReportDate() {
       return reportDate;
       }
       public void setReportDate(Date date) {
       this.reportDate = date;
       }
      
      
      }
      


      And the SQL created from that entity is like this
       alter table Report
       add constraint FK91B14154EE046B3A
       foreign key (workType_id)
       references Classificators;
      
       alter table Report
       add constraint FK91B141545BD8D7EC
       foreign key (project_id)
       references Project;
      
       alter table Report
       add constraint FK91B141542860EA88
       foreign key (person_id)
       references Person;
      
      


      My question is, how is possible to change foreign-key name from FK91B141542860EA88 to this fk_test_key

      Thanks for alla help

      Taavi