aspose file tools*
The moose likes Object Relational Mapping and the fly likes What is wrong with this Hibernate annotation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "What is wrong with this Hibernate annotation?" Watch "What is wrong with this Hibernate annotation?" New topic
Author

What is wrong with this Hibernate annotation?

William Fernandes
Greenhorn

Joined: Jul 21, 2008
Posts: 16
Hello guys!

I'm beginning with Hibernate and I read a tutorial, telling how to do one-to-many relation using annotations. Exactly what I wanted to know.

It's very simple: one course has many students.





It actually saves in the database, but in the Student table the code (of the course, FK) is NULL.
The tables were created based on these annotations, it's really the same thing.

As I copied a lot of things from the tutorial (it was very alike) there are some annotations I don't know what they mean, like @JoinColumn, @Fetch and @Cascade. Are they really necessary? I'd like to keep it as simple as possible.

Thanks anyway.

[ August 31, 2008: Message edited by: William Fernandes ]
[ August 31, 2008: Message edited by: William Fernandes ]

SCJP 6
"A peaceful man stands tall" — "I tremble for my country when I reflect that God is just."
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17256
    
    6

If you are generating the tables from source/annotations, and you are using Generics, you can get away with just

@OneToMany and

@ManyToOne only with cascade types though. I recommend the following. Try that out.



Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is wrong with this Hibernate annotation?