File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate mapping issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate mapping issue" Watch "hibernate mapping issue" New topic
Author

hibernate mapping issue

jay desi
Greenhorn

Joined: Jul 02, 2009
Posts: 27
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 02, 2009
Posts: 27
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Jul 02, 2009
Posts: 27
thanks cameron...Oh and going through some tutorials mentioned in your signature..They seem to be very good.
jay desi
Greenhorn

Joined: Jul 02, 2009
Posts: 27
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
 
subject: hibernate mapping issue