title: Eclipse: generate entities from MySQL - why there is DAO methods in entities?
body: <p>I am trying to generate JPA entities from MySQL. I using Hibenate. I read <a href="http://www.eclipse.org/webtools/dali/docs/3.2/user_guide/reference001.htm" rel="nofollow">http://www.eclipse.org/webtools/dali/docs/3.2/user_guide/reference001.htm</a> .</p>
  
  <p>This is part of my database:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `countries` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(45) NOT NULL,
    `code` CHAR(2) NOT NULL COMMENT 'ISO 3166-1 alpha-2',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `code_UNIQUE` (`code` ASC))
  ENGINE = InnoDB;
  
  CREATE TABLE IF NOT EXISTS `contacts` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `street` VARCHAR(45) NULL,
    `city` VARCHAR(45) NOT NULL,
    `psc` VARCHAR(45) NULL,
    `state` VARCHAR(45) NOT NULL,
    `phone` VARCHAR(45) NULL,
    `countries_id` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_contacts_countries1_idx` (`countries_id` ASC),
    CONSTRAINT `fk_contacts_countries1`
      FOREIGN KEY (`countries_id`)
      REFERENCES `countries` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  </code></pre>
  
  <p>Eclipse generate these entities:</p>
  
  <pre><code>@Entity
  @Table(name="countries")
  @NamedQuery(name="Country.findAll", query="SELECT c FROM Country c")
  public class Country implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private int id;
  
      private String code;
  
      private String name;
  
      //bi-directional many-to-one association to Contact
      @OneToMany(mappedBy="country")
      private List&lt;Contact&gt; contacts;
  
      public Country() {
      }
  
      public int getId() {
          return this.id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getCode() {
          return this.code;
      }
  
      public void setCode(String code) {
          this.code = code;
      }
  
      public String getName() {
          return this.name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public List&lt;Contact&gt; getContacts() {
          return this.contacts;
      }
  
      public void setContacts(List&lt;Contact&gt; contacts) {
          this.contacts = contacts;
      }
  
      public Contact addContact(Contact contact) {
          getContacts().add(contact);
          contact.setCountry(this);
  
          return contact;
      }
  
      public Contact removeContact(Contact contact) {
          getContacts().remove(contact);
          contact.setCountry(null);
  
          return contact;
      }
  
  }
  </code></pre>
  
  <p>Class Contact looks similar.</p>
  
  <p>Why there are methods "addContact" and "removeContact"? Is it good idea? I always used to CRUD dao and service class.</p>
  
  <p>What is better? "addContact" / "removeContact" methods, or delete it and put this functionality to dao/service class?</p>