-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate create a foreign key to the column itself
PostPosted: Sun Apr 14, 2013 6:32 pm 
Newbie

Joined: Sun Apr 14, 2013 6:25 pm
Posts: 1
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.

In the log I could see a line:

DEBUG org.hibernate.SQL - alter table Device add index FK79D00A76C682495E (id), add constraint FK79D00A76C682495E foreign key (id) references Device (id)

Other table with similar table seems fine. and this seems to be true for both MySQL and DerbyDB. I'm using hibernate 4.1.4

I would like to do some debug to see exactly how this happened, can anyone suggest which class in hibernate I should look at?

the annotated class is as follow.
Code:
@Indexed
@Entity(name = "Device")
@NamedQueries({
      @NamedQuery(name = "Device.findByIdentifier", query = "select d from Device d where d.identifier = ?1"),
      @NamedQuery(name = "Device.findByLink", query = "select d from Device d where d.link = ?1"),
      @NamedQuery(name = "Device.findByType", query = "select d from Device d where d.type = ?1"),
      @NamedQuery(name = "Device.findAll", query = "select d from Device d")})
public class Device extends DomainObject implements Searchable {

   @Column(name = "Type")
   @Enumerated(EnumType.STRING)
   private DeviceTypeEnum type = DeviceTypeEnum.AccessControlDevice;

   @Fields({@Field, @Field(name = "ALL")})
   @Column(name = "Name", length = Constance.DATABASE_NAME_FIELD_LENGTH)
   private String name;

   @Column(name = "Identifier", length = Constance.DATABASE_IDENTIFIER_FIELD_LENGTH, unique = true)
   @Fields({@Field, @Field(name = "ALL")})
   private String identifier;

   @ManyToMany
   @LazyCollection(LazyCollectionOption.FALSE)
   @JoinTable(name = "Device2Group", joinColumns = {@JoinColumn(name = "DeviceID")}, inverseJoinColumns = {@JoinColumn(name = "DeviceGroupID")})
   private List<DeviceGroup> groups = new ArrayList<DeviceGroup>();

   @ManyToOne
   @JoinColumn(name = "location", insertable = false, updatable = false)
   private Location location;

   @Column(name = "location")
   private Long locationId;

   @Embedded
   private SerialDeviceAddress address;

   @ManyToOne
   @JoinColumn(name = "Link", nullable = false, insertable = false, updatable = false)
   private Link link;

   @Column(name = "Link", nullable = false)
   private Long linkId;
}

@MappedSuperclass
public abstract class DomainObject extends BasicJavaBeanModel implements
      Serializable, WithID {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   protected Long id;

   public Long getId() {
      return this.id;
   }

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.