1、Spring 默认是捕捉到unchecked异常,如RuntimeException才回滚事务的。
2、ObjectOutputStream 和socket.getOutputStream()结合使用时不能连续获取流中的信息,ObjectOutputStream.writeObject(message);一次只能传递一个对象然后关闭流。由于ObjectOutputStream 每一次启动写操作时都会写入一个标记头,造成读入时只能读取第一个写入的记录。
3、使用hibernate查询关联表时,如查询其关联的数据也同时取出放入内存中,则需要在关联Annotation上指定fetch = FetchType.EAGER,否则会报错,如:
“failed to lazily initialize a collection of role: com.eyu.train.svn.module.entity.Role.accounts, no session or session was closed”
fetch = FetchType.EAGER表示取出这条数据时,它关联的数据也同时取出放入内存中;
fetch = FetchType.LAZY表示取出这条数据时,它关联的数据并不取出来,在同一个session中,什么时候要用,就什么时候取(再次访问数据库)。
但是,在session外,就不能再取了。用EAGER时,因为在内存里,所以在session外也可以取。
4、HQL中的elements使用,可以查询实体中Set或List集合中的元素。如:
from Blog, Book
where Blog.author in elements(Book.authors)
and Book.id=?
相当于sql语句:
select blog.*
from blog, book
where (blog.author in ( select author.authorid
from book_author
where book.id=book_author.bookid))
and book.id=?
5、org.apache.commons.codec.digest.DigestUtils;jar包的pom.xml
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
<optional>true</optional>
</dependency>