Steve Daskam

Greenhorn
+ Follow
since Mar 04, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Steve Daskam

Hi all,

I am trying to do a cascading delete for a one-to-many relationship in hibernate, which works OK, but does not perform efficiently. When hibernate performs the delete, it issues a separate delete statement for each child object. What do I have to do to tell hibernate to use the foreign key of the parent object to perform the delete in one shot (instead of deleting each individual child object separately)? Below is my code:





Thanks!!
Thanks, Mark!! That makes sense. So one more question: If I retrieve the Product separately, and add it to the collection in the Order class, how do I tell hibernate not to try to retrieve the all of the Products when I make a call to the getProducts( ) method? If the FetchType is set to LAZY, when I go to get the Product list, it again tries to retrieve the entire list and populate the collection.

Thanks,
Steve
Hi All,

I have an instance where I want to retrieve only a partial object graph, but can't seem to work out how to do it.

Here is the scenario:
I have an Order class that contains many products. At times, I want to retrieve the order and ALL of its products, and other times, I want to retrieve the order and only ONE of it's products. The example below is a simplification of my REAL graph where the Product class also contains several one-to-many relationships, thus the reason why I only want ONE product so that I can cut down on the amount of data that I retrieve at a given time.

Below are my classes:



So, my question is how can I do it? I have tried creating a criteria object as shown below. Hibernate creates the select statement correctly, but then immediately creates another select statement that retrieves ALL of the products, thus nullifying the first select. Is there some way of telling hibernate not to try to eagerly retrieve all of the products? And if I set the FetchType to lazy, even then when I call getProducts( ) it retrieves ALL of the products.



Thanks,
Steve
Can you please give a code example of this scenario? Will it work if there is a foreign key relationship?

Thanks,
Steve
Excellent score!! Congrats!!
Way to go, man. That's great!!
16 years ago
John,

From what I understand, you do not have to take the essay exam again. You only have to re-upload your assignment.

Regards,
Steve
Vathanak,

I didn't really handle the scenario that you describe. I just noted in javadoc that the lock method MUST be called before those methods and the unlock method MUST be called after those methods.

Steve
Just thought of a third option that I considered which is also valid. You could create a separate data factory class and pass in the file name to it. In the factory, you would just have a check to see if the data class is already created and if not, create it with the given file name. Somehow I forgot about this option while I was coding or I probably would have chosen it.

Regards,
Steve
I had some internal turmoil about creating the singleton, but decided that it was the way to go as it seemed to make my design simpler. So I went through the different possibilities.

I decided against getInstance(fileName) as this could be misconstrued as allowing multiple instances (which I didn't want), and it also turns the class into more of a factory. So I came up with a couple of different alternatives:
1) Set a System property with the file name before calling getInstance()
2) Set the file name via a static initialization method

Overall, I wasn't completely thrilled with either of these alternatives, but ended up going with option 2.
Gaurav,

I would recommend this book by Monkhouse and Camerlengo (it's great):
http://www.amazon.com/SCJD-Exam-Second-Experts-Voice/dp/1590595165/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1216141967&sr=8-1

As for the order of the exams, it's really up to you. They are very different unrelated tests. The SCWCD is a multiple-choice, drag-n-drop, short answer type of test that is focused on java web-related topics, whereas, the SCJD is a hands-on java application. I did the SCWCD test first (a few years ago) as I was wanting a better foundation in the web technology. I just now took the SCJD exam as I have been meaning to take it for a good while, and have just now gotten around to it. Also, I made it one of my personal goals (for work), so I was somewhat forced to finish it.

Anyway, whatever order you take them is fine. I think in my case, I usually go by what I am most interested in studying/working on at the time (i.e whatever will hold my interest).

Regards,
Steve
Hi All,

Just found out that I passed the SCJD exam with a score of 387. Here's my breakdown:

General Con: 96
Documentation: 70
OOD: 30
GUI: 31
Locking: 80
Data Store: 40
Network Server: 40
Total: 387 (97%)

Like others, I'm not sure about the score on the GUI. I thought that I had a pretty good design. I created the app as an MDI application with a menu, and used some popup dialogs for searching and booking. It's very extensible, but maybe it was overkill. Who knows? Anyway, I'm glad that I passed!!

I worked on the app for about 3 months (in my spare time). I used the Monkhouse book and this forum as my primary resources.

I created a mult-tiered architecture, used RMI, and my data access object was implemented as a singleton which used a single RandomAccessFile object. I just used text files for my documentation.

My advice is to read the specs carefully, and keep your implementation simple. I am happy with my design, but I think that in a few places I went beyond what the specs were asking for.

Good Luck to all of you on your exams!!

Take Care,

Steve Daskam
SCJP, SCWCD, SCJD
Gilles,

Mohamed has the correct approach to handle this situation. I have worked on many projects and the preferred approach is usually to use optimistic locking, which means that if two users obtain the same record, and one updates, then the other updates (and fails), an error message is sent back to the second updater telling him that he needs to re-retrieve the data and try again. Typically, there is some kind of update value (such as an update-timestamp) that is checked to see if the retrieved record is still in sync with the record in the database. I hope that makes sense.

Regards,
Steve