Having a long field on an entity managed by hibernate could be dangerous with null values. When Hibernate tries to set a null into a primitive an exception will be thrown.
Best solution should be to use Long instead of long, so null can be assigned to Long field.
But, I'm working on a project where we can't use Long or Integer types. I'm wondering if there is a way to override hibernate types to use a nullSafe method or something like that.
At finally I've get it implementing UserType
of hibernate as explained here: http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch06.html#types-custom