This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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.

 
The knights of nee want a shrubbery. And a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!