-->
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: Collection - Foreign key wrong number of columns error
PostPosted: Thu Dec 02, 2010 11:53 am 
Beginner
Beginner

Joined: Fri Nov 13, 2009 4:05 pm
Posts: 30
I am trying to relate an entity to a collection in my system where this collection is associated to another entity object as well. We originally had the following entities:

Code:
// ItemId entity
public class ItemId implements Serializable {
  private Long itemId;
  private Long plantId;
 
  @Column(name="ITEM_ID",unique=false,nullable=false,insertable=true,updatable=true,scale=0)
  public Long getItemId() { return itemId; }
  public void setItemId(Long itemId) { this.itemId = itemId; }

  @Column(name="PLANT_ID",unique=false,nullable=false,insertable=true,updatable=true,scale=0)
  public Long getPlantId() { return plantId; }
  public void setPlantId(Long plantId) { this.plantId = plantId; }

  // hashCode/equals
}

// Item entity
public class Item implements Serializable {
  private ItemId id;

  @EmbeddedId
  public ItemId getId() { return id; }
  public void setId(ItemId id) { this.id = id; }

  @OneToMany(fetch=FetchType.LAZY,mappedby="item")
  public List<ItemText> getTexts() { return texts; }
  public void setTexts(List<ItemText> texts) { this.texts = texts; }

};

// Item Text
public class ItemText implements Serializable
{
  private ItemTextId id;
  // more stuff

  @EmbeddedId
  public ItemTextId getId() { return id; }
  public void setId(ItemTextId id) { this.id = id; }

  @ManyToOne
  @JoinColumns({
    @JoinColumn(name="ITEM_ID",insertable=false,updatable=false),
    @JoinColumn(name="PLANT_ID",insertable=false,updatable=false)
  })
  public Item getItem() { return item; }
  public void setItem(Item item) { this.item = item; }
}


We now need to create another entity based on a database view, called ItemSearchView and what I would like to do is be able to associate the ItemText collection in this view just like I did with the Item entity above. The problem is if I do that, I get a collection foreign key exception:

Caused by: org.hibernate.AnnotationException: A Foreign key refering com.setech.seek.hibernate.model.ItemSearchV from com.setech.seek.hibernate.model.ItemText has the wrong number of column. should be 1
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:429)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1443)
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1262)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:693)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:628)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)

Is it not possible for me to do a @ManyToMany associate in my View object to ItemText but also have a @OneToMany relationship between Item and ItemText simultaneously ??? If so, what do I need to change to accomplish this?


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.