• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JPA Mapping exception repeated column in mapping help requested

 
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
 
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.

 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic