Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate mapping issue

 
jay desi
Greenhorn
Posts: 27
  • 0
  • 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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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
  • 0
  • 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..
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic