Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Anyone know how to construct a one to many mapping with Hibernate / Java?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using Hibernate 3.4.0.GA. I have two objects mapped to database tables (defined in hibernate.cfg.xml like so):



In the database tables, a row from the VENDOR table (primary key column = VENDOR_ID), could map to zero or many rows in the VENDOR_EMAILS table, which has the corresponding column, VENDOR_ID, which is a foreign key. In my "YouthfulDriverVendor" model class, I defined the one to many (vendor to one or multiple emails) like so ...



However, I'm getting this error ...

Repeated column in mapping for collection: myco.dor.dmv.driver.youthful.model.YouthfulDriverVendor.emails column: VENDOR_ID
org.hibernate.MappingException: Repeated column in mapping for collection: myco.dor.dmv.driver.youthful.model.YouthfulDriverVendor.emails column: VENDOR_ID
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:329)
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:352)
at org.hibernate.mapping.Collection.validate(Collection.java:309)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1139)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
.....

What adjustments do I need to make to fix the error I'm getting? Thanks, - Dave
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


@JoinTable(name = "VENDOR_EMAILS",
joinColumns = {
@JoinColumn(name="VENDOR_ID", unique = true)
},
inverseJoinColumns = {
@JoinColumn(name="VENDOR_ID")
}



I think that joinColumns and inverseJoinColumns refer to the same table VENDOR_EMAILS, so you are creating 2 columns with the same name.
The inverseJoinColumns could be emails_id

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that got me passed that problem. Was wondering if you had any reaction to the next problem I encountered. Stack trace below. It happened in response to my attempt to get the list (collection) --



Thanks again for the help, - Dave

 
Silvana Donato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that this means that you are trying to get a collection that has not actually been retrieved by the db yet.
You can try to set fetch property to fetchtype.eager in the annotation of the collection property.
Something like:

@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)

 
Hot dog! An advertiser loves us THIS much:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic