• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA Mapping exception repeated column in mapping help requested

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot sir. it makes perfect sense.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic