遇到的一些东西

1.
session.beginTransaction() == session.getTransaction().begin()
所以不用再调用transaction.begin()了。
2.
getCurrentSession创建的session会和绑定到当前线程,而openSession不会。
getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSession必须手动关闭。
用spring的话用getCurrentSession比较好。
3.
单纯的hibernate出错时不会自动rollback,但是用spring的话在beginTransaction和commit之间出错是会自动rollback的。
4.
关于Hibernate的 Batch update returned unexpected row count from update异常,
可能是由于使用了saveOrUpdate,其根据id(primary key)是否为null来判断是save还是update。
5.
我也遇到这个问题了,查询也需要开事务??http://bbs.csdn.net/topics/390218467
6.
DAO类最好还是写成模板类,毕竟好多都是相同的操作,但是模板类里面的session.get的第一个参数不知道怎么填写。此外,想把Service类也写成模板,可能会利用到java的反射机制,推荐
侯捷的Java反射机制
7.
使用hql的时候,直接写入了"from Problems where pid<=? and pid>=?"结果一直说Problems not mapped,后来改成"from " + Problem.class.getName() + " where pid<=? and pid>=?"就可以了,不知道为什么……(我Problem实体类里面写的是Entity("Problems")啊。。)
8.
把MySQL换成了MariaDB,发现原来可以跑的create procedure之类的都出错误了:

 This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
Google了一下,发现只要先SET GLOBAL log_bin_trust_function_creators = 1;就可以了~
9.

MariaDB(MySQL)导入大批量数据,可以set commit=0之后再导入,速度会快很多。
另外一个加速是暂时禁用外键约束的检查:

禁用
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0
启用
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS
待导入完成之后再启用。
10.
hibernate的映射实在没搞清楚,这个时候(为了赶时间)索性就不要用映射了……
11.
<c:if test="${not guest}">
    <form>
        <input type="text" placeholder="Your comment here"></input>
        <input type="submit" value="Post"></input>
    </form>
</c:if>
test后直接加boolean,el表达式里面可以用not。
12. Mongoose Schema为Object类型field的修改
见: https://github.com/LearnBoost/mongoose/issues/1106

主要就是说mongoose不知道内部的Object是啥结构,如果要改内部的Object,那么必须save前先mark一下。

var NewPlayer = new Data.model.player;
NewPlayer.email = data.email;
NewPlayer.password = password.digest('hex');
NewPlayer.birthday = new Date(data.birthday);
NewPlayer.player = new Player();
NewPlayer.player.position.x = 0;
NewPlayer.player.position.y = 0;
NewPlayer.save(function(err){
    NewPlayer.player.position.x = 100;
    NewPlayer.save();
});

in schemas, Object is the same as Mixed, bc everything inherits from Object. Mongoose doesn't know about properties inside of mixed types (NewPlayer.player.anything) and does not get informed of the changes. To tell mongoose about your change, use NewPlayer.markModified('player.position.x') before your last save.

你可能感兴趣的:(遇到的一些东西)