我个人觉得你在调用一个api之前,应该好好看看api的注释。 下面是Hibernate的Session对象的save()方法的注释。你看看他的“@return the generated identifier”,是不是很明显? /** * Persist the given transient instance, first assigning a generated identifier. (Or * using the current value of the identifier property if the <tt>assigned</tt> * generator is used.) This operation cascades to associated instances if the * association is mapped with <tt>cascade="save-update"</tt>. * * @param object a transient instance of a persistent class * @return the generated identifier * @throws HibernateException */ public Serializable save(Object object) throws HibernateException;
下面是Hibernate的Session对象的save()方法的注释。你看看他的“@return the generated identifier”,是不是很明显? /**
* Persist the given transient instance, first assigning a generated identifier. (Or
* using the current value of the identifier property if the <tt>assigned</tt>
* generator is used.) This operation cascades to associated instances if the
* association is mapped with <tt>cascade="save-update"</tt>.
*
* @param object a transient instance of a persistent class
* @return the generated identifier
* @throws HibernateException
*/
public Serializable save(Object object) throws HibernateException;