Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Mapping exception repeated column in mapping help requested

 
krishna viswakarma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to design the following in JPA which uses hibernate.

consider a table called products. Which contains a bunch of products as it says :-)

I have another table which stores the relationships between these products, which can be parent child grandchild and so on and so forth.

product
{
@Id @generatedvalue
private int productId;
}

product relationship
{
@Id @generatedValue
int relationshipId

@ManyToOne
@JoinColumn(name="productId")
private product fromThisProduct;

@ManyToOne
@JoinColumn(name="productId")
private product toThisProduct;

@ManyToOne
@JoinColumn(name="relationshipDefId")
private relationship parentrelationship;

}

it forces me to use insertable as false and updateable as false for one of them but that does not help me since it does not store the relationship between the products. I am not sure how to get over this and continue.
if you have some ideas please help me out, also i am willing to change my DB design if there is a better one but i cant think of any.

thanks for taking time and helping me.

thanks
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi krishna,

as far as I know the attribute name of the annotation JoinColumn is the name of the column in this table, not in the referenced one (which would be referencedColumnName, but can be omitted if the pk column is referenced).

In your case this would mean that you're trying to have two columns named productId in your database table productrelationship.

Try to rename them, e.g.:




John
 
krishna viswakarma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot sir. it makes perfect sense.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic