jherbst wrote:
Hi,
please post your mapping files. Seems like you're mapping is wrong or you're database has problems generating the identifier.
Joerg
Don't forget to rate!
Joerg is right about the mapping files. However, I guess we can safely ignore the "problem while generating identifier" assumption, since you are able to get it working with save().
From the stacktrace it is evident that Hibernate is (wrongly) considering your FuelType object as detached instead of transient. Consequently, it is actually trying to
update the object, instead of saving it. This also explains why it is (unnecessarily) cribbing about the id being null, and also why calling "save(...)" explicitly is working fine.
The relevant Hibernate code that does this check is the
ForeignKeys.isTransient(...) method. Now, the first line of this method seems promising :
Code:
Boolean isUnsaved = session.getInterceptor().isTransient(entity);
....considering the fact that you have configured your own interceptor :
Code:
new Configuration().configure(url1).setInterceptor(interceptor).buildSessionFactory();
So, I guess you need to check your Interceptor implementation, w.r.t the
isTransient(entity) method. Unless it is returning null (like the default EmptyInterceptor), there is a strong chance that your interceptor might be at fault.
If the interceptor comes clean, it could be that you have specified an incorrect value for the "unsaved-value" setting for the identity property of FuelType entity. The mapping files would come handy in figuring out that.