My Personal Online Recycle Bin
You may find something useful here...........

Thursday, May 25, 2006

Using xdoclet to generate hibernate one to many relation

How to generate one to many hibernate relation with xdoclet.

I begin with looking at the sample availabe in the internet and ebook. Both of the resource bring me to something like this...

/**
* @hibernate.set cascade = "save-update"
* lazy = "true" inverse = "false"
*
* @hibernate.collection-one-to-many class = "com.xxx.yyy.ggg.vo.ManySide"
* @hibernate.collection-key column = "fk_OneSide"
*/
public Set getXxxSet() {
return manySet;
}

public void setXxxSet(Set xxxSet) {
this.xxxSet = xxxSet;
}


I tried it out. But it give me the following error:

Reason: java.lang.RuntimeException: no element tag deined in class YYY for xxxSet

Then i tried to solved it using a lot different way. After one day searching on my best friend (google). Finally i come to this url that solved my problem easily.

The solution is just to remove the "collection" word. The solution is as follow:

/**
* @hibernate.set cascade = "save-update"
* lazy = "true" inverse = "false"
*
* @hibernate.one-to-many class = "com.xxx.yyy.ggg.vo.ManySide"
* @hibernate.key column = "fk_OneSide"
*/
public Set getXxxSet() {
return manySet;
}

public void setXxxSet(Set xxxSet) {
this.xxxSet = xxxSet;
}


The problem is due to the fact that i am using xdoclet2 from maven instead of xdoclet1 from sourceforge. Thus they have different syntax.

Sunday, May 21, 2006

Calendar.HOUR vs Calendar.HOUR_OF_DAY

Beware when u are using calendar to set the time...

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
System.out.println("calendar is set to " + calendar.getTime);

You may expect it to always print "calendar is set to yyyy/mm/dd 00:00:00"

But this is not the case.

it will print "calendar is set to yyyy/mm/dd 00:00:00" if the execution time is AM
else it will print "calendar is set to yyyy/mm/dd 12:00:00" if the execution time is PM.

used Calendar.HOUR_OF_DAY to make the output always print "calendar is set to yyyy/mm/dd 00:00:00".

Below is the description from java sun api for Calendar.HOUR and Calendar.HOUR_OF_DAY

Calendar.HOUR = Field number for get and set indicating the hour of the morning or afternoon. HOUR is used for the 12-hour clock. E.g., at 10:04:15.250 PM the HOUR is 10.

Calendar.HOUR_OF_DAY = Field number for get and set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.

Tuesday, May 02, 2006

NotSerializableException, Session Replication with jboss

Last friday, Jboss thrown NotSerializableException to me after i add in session replication in jboss.

I quickly knew that some of the class that is add into session is not implementing serializable.

Serializable allow object state to be saved and retrieved to another external source. Since anything add to session in one jboss need to also add to another jboss for session replication purpose, thus any class that may need to stored in session must implement serializable interface.

Serializable is just a marker interface, no method need to be inherited or override in order to make it work. Anyway, it was always a good pratice to include "serialVersionUID" if serializable is implemented.

So, today i have learn
any class that may need to stored in session should always implement serializable interface