Going into hibernation involves saving the machine's state (e.g. all RAM content) to a hard disk file. This usually will take at least some seconds and cannot be done without power supply. There are some capacitors in the mains adapter, but they're only for very short power interruptions.
You could either use a notebook (with an integrated battery pack), or get an uninterruptible power supply ("UPS") - that's kind of an external battery pack, which might last for anything from minutes to hours (depending on load and size). Most UPS types then can notify your computer via USB or network, so your machine can go into hibernation, if the battery capacity drops under (say) 15%. When power is restored, the UPS will automatically recharge.