If S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that

Sounds confusing? It sure does to me at least.

Here is an easier version

If you have sub-classed a given class- in that case any program that uses your parent class via  a pointer or a reference – should continue to be able use any of the sub class that it may get instead of the Parent class- without any change in behaviour.

Now why is this important ?

Polymorphism was designed to provide a run-time binding that would make possible to use a different set of behavior depending upon the context. Which is all nice and cool- except that when you switch the behavior with another behavior which is semantically not compatible with the behavior of the parent class

Example- when its violated

We have a class Product. This has a method- order().The behavior of this method is that it places an order with  the vendor.

Now your inventoryControl System uses many Products and uses this method to order goods.

We decide to introduce a new range of products- Guns.

And since this needs authorization- the Guns class instead of placing the order with the vendor- sends an email to the Manager.

This would serve the purpose of informing the Manager that someone wants to purchase a Gun and may initiate a sequence of events leading to that. But it would create confusion for the system which would be waiting for a conformation from the vendor that the order was placed or may start a check as to why the Vendor hasn’t received an order yet…

Whenever you extend a class and override an already implemented method- watch out.You need to make sure that you are not violating the contract established by the Parent class. In contrast – its OK to override abstract methods.

Design by Contract (Dbc)

This principle leads to a very parallel concept- Design by Contract

What this basically says is – that whenever you subclass-

A) You should not impose newer or  stricter preconditions. Example : The method in the parent class accepts an int type parameter and has no problem with a negative value. If the method in the child class is unable to handle negative parameters while the parent class can- we are violating Dbc.

B) You cant weaken the post-conditions. Example: The method in the base class- places an order with a vendor and send you a confirmation email. If the method in your child class- simply places an order- but fails to send a confirmation email- it is violating Dbc.

On the same lines- a method in the child class- cant throw an exception- which is not in the throws class of the Prent class. The obvious reason is that the programs using references to parent class- would not be coded to handle this exception .

Who do we thank for this ?

Barbara Liskov: http://en.wikipedia.org/wiki/Barbara_Liskov

Interactive Software Engineering for Design by contract


The error message

Named query not known: my.simple.query
    [junit] org.hibernate.MappingException: Named query not known: relationship.delete_by_userId
    [junit]  at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:93)
    [junit]  at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1287)

The context

You are using a named query in your application. Named queries are externalized and are coded in the hibernate mapping files rather than the application code

Possible reason(s) for this error

1) The name of the query in the hibernate file doesnt match with what you have in the code. Both should match exactly

2) You have defined the query inside the class definition. A hibernate mapping file can have multiple class definitions (not a recomended or much practised approach though). A named query must exist outside the class definition.


<query name=”my.simple.query”>delete from Users as user where user.id =?</query

Session session = sessionFactory.openSession();
Query query = session.getNamedQuery(“my.simple.query”);
query.executeUpdate ();

Did this solve your problem ?

Please let me know. Thanks !!!


I think open systems are very much like democracy.

And I would say i-Series is akin to a closed world society like a socialist country.

If you think about it- you will find that there are quite a few similarities between open systems and democracy.

Both are run by the people. Well to an extent – I guess. Finally some big-wig does come in and has the final say.The revisions in a open systems is quite  like the elections in a democracy.Every now and then we come together again to debate who has the best possible solution to the worlds problem. We argue endlessly and finally each party goes back to their room declaring themselves as the winner and passionately declare the other’s agenda as the path to chaos.

The other wide- closed systems like iSeries- the road is lot more smoother.There are few arguments and life is lot more predictable. Maybe less excitement but i wouldn’t doubt that it is full of pleasure. Sometimes it may seem too autocratic- less glamorous- but it works- at least for some and they seem to have few complains

The other day- I met our famous i-Series team who are behind an amazing WMS system

We started comparing jokes and notes about how life is on both side. I have little or no knowledge on how i-Series like systems work- the concept that the OS\DB\Server- is all one and the same.

So I (mock-)asked them- “Does it ever happen to you- that you spend an year learning a fremework and suddenly realize that the whole world while you were asleep has discovered yet another framework- which is really the end-all? And then you start all over again…”

 Dont take me wrong- I love Democracy and oh well I like open systems as well

But seriously- sometimes I think its gettting a bit too crazy

Last week- I setup my tomcat server and wrote a small JSF application. Nothing ambitious – just a hello-world program. And it was quite a ride.

Its amazing how this concept even works…

I downloaded some quick tutorial and did some obvious and minor modifications to it

And then – it was an error after another…

And the funny part was when I would google on the errors I was getting- it was a road much travelled

I felt as if I was walking in peoples foot steps

Scores of people had done the same thing as I was doing- and they had the same errors.Same resolutions- same dead ends.It was uncanny…

I dont blame the nice people who put those tutorials and resoltions to problems out there – I am sure they worked at some point and were correct piece of advice.

But then came in the newer version of JSF,Java ,J2ee and what nots- and those stopped working

Sometimes- you need another class file in the lib, sometimes another entry in a config file and sometimes a small tweak in the name of the DTD fiel your XML file was refering to.

I think we have run amok with this whole freedom.

I am sure its for the betterment of human being and will be the solution to the Global warming as well – but then I am sure – we will find multiple soltions to Global warming a well

© 2011 Technology Cafe Suffusion theme by Sayontan Sinha