• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate newbie question

 
Nakataa Kokuyo
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day,

I'm facing dilemma of short timeline about 2-3 days to handle left over task, while I still picking up on Hibernate, I need to handle three scenario but i'm not sure how to write the correct hbm config file.

The scenarios :

1. having set of records under a collection - set, these record will need to insert into table-SchoolReference and generate the id in incremental way. the Db will store many records with format <schoolID, schoolName>, in this case, studentID is auto generated.

2. have a list with records of few columns which need to be insert into another table-SchoolConversion. Scenario: student from this school change to another school, format <beforeSchoolID, beforeSchoolName, afterNewSchoolID, AfterNewSchoolName>.

3. When giving the school id, I need to find from schoolconversion table, what are the related schoolID for before and after conversion.

Appreciated your guidance on this, thanks in advance!
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this homework?

I am not sure what you are looking for.

1. I would write out your requirements on some paper or a white board and start figuring out what your domain objects should look like. Applications should be written in terms of the domain model, while you are doing this forget all about tables and columns. Your application should not be bound to the relational model. You should operate on the domain model without having to express it in the relational language of tables, columns, and keys.

2. Next forget about everything you were doing in #1 and think about table design. What data do you have to store and what is the most efficient way to store it ? Create the tables accordingly.

3. Now after 1 and 2 you map the domain objects to the tables and columns. This is the step where you will annotate your domain objects or create a hibernate mapping xml.

It sounds to me like you might be skipping steps 1 and 2. I would encourage you to back up a bit and do those first two steps first and then try step 3. If you encounter specific difficulties post back with them.
 
Nakataa Kokuyo
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill,

for item1, it purely just save the data like a lookup table for key and name reference, it doesn't have relationship like 1:1 or 1:m, can we save the set without define relationship?

Is there any recommended site or book i should reference? there are many but i would appreciated if you can specify it since i got limited time here for this.

FYI, it is commercial project where my colleague just resign in short notice and i have cover it for deadline
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we save the set without define relationship?


Sure @Table and @Column annotations (or equivalent mapping file if using xml) would be all you need in that case.


Is there any recommended site or book i should reference?


I like Pro JPA2

There are lots of sites out there. Often times though the one that will help depends on the problem you are having. Google is your best friend in this case.

Good luck!
 
Nakataa Kokuyo
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill , many thanks !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic