title: Hibernate create foreign key to itself
body: <p>I have a very strange problem with hibernate at the moment. 
  Somehow on a table, it create a foreign key which reference to itself. the column is also a primary key. This essentially prevent me from delete any row from that table. </p>
  
  <p>In the log I could see a line:</p>
  
  <blockquote>
    <p>DEBUG org.hibernate.SQL - alter table Device add index
    FK79D00A76C682495E (id), add constraint FK79D00A76C682495E foreign key
    (id) references Device (id)</p>
  </blockquote>
  
  <p>Other table with similar table seems fine. and this seems to be true for both MySQL and Derby. I'm using hibernate 4.1.4</p>
  
  <p>the annotated class is as follow.</p>
  
  <pre><code>@Entity(name = "Device")
  public class Device extends DomainObject implements Searchable {
  
      @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  protected long id;
  
      @Column(name = "Type")
      @Enumerated(EnumType.STRING)
      private DeviceTypeEnum type = DeviceTypeEnum.AccessControlDevice;
  
      @Column(name = "Name", length = Constance.DATABASE_NAME_FIELD_LENGTH)
      private String name;
  
      @Column(name = "Description", length = Constance.DATABASE_DESCRIPTION_FIELD_LENGTH)
      private String description;
  
      @Column(name = "Identifier", length = Constance.DATABASE_IDENTIFIER_FIELD_LENGTH, unique = true)
      private String identifier;
  
      @ManyToMany
      @JoinTable(name = "Device2Group", joinColumns = {@JoinColumn(name = "DeviceID")}, inverseJoinColumns = {@JoinColumn(name = "DeviceGroupID")})
      private List&lt;DeviceGroup&gt; groups = new ArrayList&lt;DeviceGroup&gt;();
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "location")
      private Location location;
  
      @ManyToOne(cascade = {CascadeType.ALL})
      @JoinColumn(name = "Address")
      private Address address;
  
  
      @ManyToOne
      @JoinColumn(name = "Link", nullable = false)
      private Link link;
  }
  </code></pre>