Sunday, June 22, 2008

About Hibernate Save and Delete parent children again

I want to add new child object into children collections and remove 'selected' existing child object from the same children collections.

  1. First, i get the collection from 'attached' parent. For e.g Set children = parent.getChildren()
  2. Add the new Child object. Of course please save the Child object first. children.add(newChild).
  3. Remove the 'selected' existing Child object. children.remove(removedChild)
  4. Finally, save the Parent object.

It is kind of fundamental. However sometimes we may get confused due to whatever reasons.

Wednesday, June 18, 2008

OpenOffice mail merge problems

I need to merge document B to document A(master document) using OpenOffice SDK.

My font in document B is 'Arial' and there are 3 paragrahs in it.

After merging, the font of the last paragrah somehow changed to 'Times New Roman'!

Another problem is, document A is formatted with numbering, document B is supposed to be inserted at the first line of the numbering. However, the 2nd paragraph from document B ends up a new number within the numbering format! To be more specific, document B's content should be positioned at number 5.1, but right now document B's content has been splited into 2: 5.1 which is the 1st paragraph from document B and 5.2 which is the 2nd paragraph from document B. My intention is to put all paragraphs from document B into 5.1!

After few days of searching, i discovered that it is actually a bug in OpenOffice!
  1. http://qa.openoffice.org/issues/show_bug.cgi?id=60475


  2. http://www.oooforum.org/forum/viewtopic.phtml?t=60268&highlight=insertdocumentfromurl+format
My solution:

  1. To solve the numbering problem, document B must always have an extra paragraph break after the last paragraph! (If you are using OpenOffice, click View from menu and choose to show "Nonprinting Characters")


  2. To solve the style problem, i adjust the styles in document A again after the merging is done.















Thursday, June 12, 2008

Differences between response.sendRedirect & response.forward methods

Came across one good explanation below, share with you guys out there:

Forwarding the Request and Re-Directing URL are two totally different animal. Your server gets the request from the browser..job of server is to send back the response. How how that response is generated is totally up to your server..you can process that request in one servlet or can process the same request using multiple sevlet...To process request using multiple servlet, you need to pass the request to another servlet...and ofcouse we do not want to loose the parameters/data set into the request otherwise that request does not make sense anymore.....This is all request forwarding!...Request forwarding is done during one HTTP request-response cycle..Once you return the response, you are done!

Now, In the response, you can tell your browser to do URL redirect to any other URL..this is HTTP header thing and browser will interprete the HTTP header and will send brand new request...

Thursday, June 5, 2008

Delete procedure of One to One relationship in Hibernate

I found out that Cascading does not work for 1-to1 relationship. We have to cater for it specifically.

The story is, i mapped 2 entities with each of them having a "many-to-one" relationship to represent a 1-to-1 relationship. I did not use the "1-to-1" mapping because it caused some problems which i now can not remember anymore.

Let's call the 2 entities as "parent" and "friend". 1 parent has 1 friend.

Now, I want to just delete "parent" and hope that its children will get deleted automatically.


  1. Therefore i will do a "session.delete(parent)". However this will throw an exception saying that "parent" is referencing another entity "friend".

  2. So, I will now get the "friend" from "parent" first by doing "Friend friend = parent.getFriend()".

  3. Then, i do a "parent.setFriend(null)" and saved the parent by doing "session.save(parent)". The "parent-friend" 1-to-1 relationship is being removed now.

  4. Next i delete the friend by doing "session.delete(friend)".

  5. Lastly, i will do a "session.delete(parent)". The parent will now be removed together with its children!

Hibernate Dialect

Today one problem arose. User complaint that one of the screen's query process takes too long time! I spent hours trying to figure out why. In the end found out that the Hibernate Dialect should be changed to MySQL instead of MSSQl one!

That is funny because my system is running on a MSSQL database! How can i just put MySQL dialect for Hibernate!

Well, it really speeds up the searching process.

Hell....