the Common Problems of Hibernate

1. 如何保存双向关联
When you update a bidirectional association you must update both ends.
  parent.getChildren().add(child);
  child.setParent(parent);
2. persisit和save的区别
Both methods make a transient instance persistent. However, the persist() method doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time.

The persist() method also guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context.

The save() method does not guarantee the same, it returns an identifier, and if an INSERT has to be executed to get the identifier (e.g. "identity" generator, not "sequence"), this INSERT happens immediately, no matter if you are inside or outside of a transaction. This is not good in a long-running conversation with an extended Session/persistence context.
persist不会立即执行insert语句, 也不会立即返回identity.save相反, 很及时.
3. Hibernate是否支持视图
支持视图
4. 二级缓存second level cache是不同于query cache的, 二级缓存主要被用于get(), load(),  查询缓存 must use the query cache to cache HQL, SQL, or criteria query result sets.

你可能感兴趣的:(sql,Hibernate,cache)