Tuesday, September 30, 2008

Back reference in Hibernate

I was working on a bug (enhancement) in my project, where in I had to enhance one functionality which is purely written in JSF (some JS) to use the projects metadata framework. First I want to tell what this framework looks like (at high level).

Metadata framework (MTDFRM) its some thing like replicating or showing in UI form to the user for doing addition/editing/deletion of an row in DB (database).

Coming to the problem where it all started, below is the hibernate mapping of a table which I had move it to MTDFRM from conventional JSF:

<hibernate-mapping>
<class lazy="true" update="true" insert="true" table="HOLDER" name="Holder">
.......
.......
<set lazy="true" cascade="all" name="ParamsValues">
<key column="PARAMS_VALUES_SEQNO" null="true">
<one-to-many class="ParamsValue">
</one-to-many>
</key>
</set>
.......
</hbm>

There were 10 properties (including collections) but when I was running the project JSF was complaining about a property not found which was named as _paramsValuesBackref ("_" and "Backref" where appended to paramsValues, as I am like a new bee to the project I spent around 6hours finding which code modified the properties of the table mapping but I never serached in hibernate code, my mistake :(, but some how at last I was able to trace to a file which was appending one extra property to the metadata, it was org.hibernate.cfg.HbmBinder.

As per comments in the file of HbmBinder it says "for non-inverse one-to-many, with a not-null fk, add a backref!", which was perfect fit for the above properties which I had in my mapping file, so I had to add inverse="true" which made the backref no more to be added as extra properties in the metadata, as we know it also helps in telling hibernate that we should not propagate chances made at this collection end ie at ParamsValues end.

This blog doesn't say much about the usage of BackRef by hibernate, as I need to investigate the usage as how hibernate uses this property. Will be posting the finding (need to google or debug) in the next blog to come....

Sunday, September 21, 2008

The mistakes I do & repeat it even if I know :)

I am a human :) (wow at last I think I am a human) in my job I do one big mistake, which I know about, I may be doing even more mistakes but I need to hunt them down someday.
So about this mistake, I don't know what technical word is given to this habit, its like this say I am working on a problem (off-course its about my job) and as usual I don't know anything about it, I try to hunt it down as soon as possible but when I am stuck the usual thing normal people do is take help from a person who already knows about it but me me....I don't do this but instead I hunt around and this goes like a circle, few problems yeah I do get solutions, its not gr8 because already ppl know about this and me just discovered, but my inner feeling is like "wow I did some thing gr8" this feeling is a evil in disguises to me as for other problems I hunt and I can't get the solution on time but to get this gr8 feeling I try and try but at the end it like, the problem which can be solved by a person how knows things better can do it in say some 16hour I spent the whole week :( ie 8hours * 5 (40 hours) but still I am now where.......
This is my biggest mistake, I do all over then I release but then latter when I am into problems I forget or negelate my mistake and I am allover again doing the same old mistake :)
The other mistake I do is like, when I am looking for solution for problem 'A' I hunt it down, but during this period if I see other things like 'B', 'C'.....I get involved in tooking into it for getting knowledge about them and I just get deviated from problem 'A'.
I need to over come this things, hope I do and soon as I am getting nearer to 4years of work exp I need to be more smart and more control on my self taking in to account of any problem (technically).