Fixed the check for the state of entities

- the state can only be checked for mapped classes, not for any object
  (DateTime objects in a field are transient)
- entities scheduled for insertion are in the managed state without having
  an identifier so both checks are needed.