• 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

Mapping relationship with partial composite key column

 
Ranch Hand
Posts: 37
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Working on Hibernate 3.2.4ga, calling Oracle 10. It is likely I am not setting this up properly; however, here is my case.

I have 2 legacy database tables. The first table is called "TITLES". It contains a fk with the column name "TITL_BOOK_CAT". The second table is called "BOOKCAT_ACCESS" and contains a non-generated/non-sequential composite pk of columns named "BCCA_BOOK_CATEGORY" and "BCCA_ACCESS_LVL".

My goal is to setup a relationship between the Titles and BookCatAccess entities such that each Title could have one to many BookCatAccess entities. I have tried various ways to map this relationship; however, I have not been able to get the results I expected.

Below is the source code:

@Entity
@Table(name="TITLES")
public class Titles {
...
@Column(name="TITL_BOOK_CAT")
private String titleBookCat;

...<getters and setters for titleBookCat>...

@OneToMany
@JoinColumn(name="BCCA_BOOK_CATEGORY", referencedColumnName="TITL_BOOK_CAT")
private List<BookCatAccess> bookCategoryAccessList;

...<getters and setters for bookCategoryAccessList>...

}

@Entity
@Table(name="BOOKCAT_ACCESS")
public class BookCatAccess {

@EmbeddedId
private BookCatAccessId id;

...<getters and setters for id>...

@Embeddable
public class BookCatAccessId implements Serializable {
@Column(name="BCCA_BOOK_CATEGORY")
private String bookCategory;

@Column(name="BCCA_ACCESS_LVL")
private Long accessLevel;
}
}

I do not get SQL back as this call results in a ClassCastException.

Any direction or advice would be helpful.

Mike

 
reply
    Bookmark Topic Watch Topic
  • New Topic