• 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

hibernate mapping issue

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all,

I am a hibernate newbie.

I work with an older mysql database. This schema does not have foreign-key constraints between various
tables syntactically. Although, conceptually speaking, there are many foreign-key relationships between these tables.

Eg:- This is a sample table :-







The second table ideally should have been:-




However, I cannot modify schema now.My question is that Can I still use Hibernate annotations here.
Can I still use @OneToMany if there are no foreign key constraints on database tables?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it, and wouldn't that have been quicker?

I'm not aware that Hibernate checks itself against DB metadata--all it cares about is what you tell it.
 
jay desi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david...thanks for a quick reply..
I cannot modify schema because I am not allowed to do so...its a very old db schema..
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you've got the foreign key, you just don't have the constraint, right? I think this will be okay.

-Cameron McKenzie
 
jay desi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks cameron...Oh and going through some tutorials mentioned in your signature..They seem to be very good.
 
jay desi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to create an entity class from database in netbeans using hibernate. However, one of the db table
does not have a primary key, but an index. And it didnt allow me to create an entity class frm that table.
So, I guess we cannot use hibernate to map table to object if we dont have any primary key. Am
I correct?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're trying to create it *automatically* then no--there's no way for the conversion process to read your database's mind.

Do it manually.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
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