Hammering a magnet would cause the magnetic domains to alter their alignment. This would cause a magnet to lose its magnetism.

Like hammering, heating a magnet would also result in it losing its magnetism. Energy from the heat from external source would cause the atoms of a magnet to vibrate more rigorously and hence would cause the magnet's domains to lose their alignment.

Electrical method using an alternating current (A.C.)
The most effective method of demagnetisation. Magnet is placed inside a solenoid connected to an alternating current supply as seen in the diagram of the right.
An alternating current is an electric current which varies its direction many times per second (more will be covered later).
The magnet is then slowly withdrawn in the East-West direction with the alternating current still flowing in the solenoid. 

Storage of magnets using soft iron keepers

Permanent magnets would eventually lose their magnetism one way or another as the magnetic domains would be moved out of their alignments by external factors. Storing them side by side would further reduce the time taken for these magnets to lose their magnetism. 
To prevent magnets from losing their magnetism too quickly, we store magnets in pairs by using soft iron keepers across the ends of the bar magnets (see diagram on the left). The poles of the magnets are in closed loops 'locking' the alignment of the magnetic domains.

Magnetic Fields