Add DeadlockException

Make it easier to handle deadlocks by throwing a specific exception.
Detect deadlocks using error codes
Throw exception when value is null and allowEmpty is false
Implement allowEmpty for BelongsTo. This also fixes BelongsTo being a subclass from HasOne.