aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA Mapping exception repeated column in mapping help requested Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Mapping exception repeated column in mapping help requested" Watch "JPA Mapping exception repeated column in mapping help requested" New topic
Author

JPA Mapping exception repeated column in mapping help requested

krishna viswakarma
Greenhorn

Joined: Aug 23, 2009
Posts: 2
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

Joined: Feb 12, 2009
Posts: 132
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

Joined: Aug 23, 2009
Posts: 2
thanks a lot sir. it makes perfect sense.

 
 
subject: JPA Mapping exception repeated column in mapping help requested
 
Similar Threads
Cascading deletes
Stuck on manyToMany association
JPA returning collection of type PersistentBag instead of ArrayList
Hibernate - Annotations - many to many association
Saving database records problem