1,使用環境:mysql+hibernatejava
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,mysql
hibernate save/update 的時候時間不變;sql
須要修改hibernate 映射文件hibernate
<property name="updated_at" type="java.sql.Timestamp" insert="false" update="false"> <column name="UPDATED_AT" length="19" /> </property>
2,hibernate使用外部cfg.xmlcode
String curDir = System.getProperty("user.dir"); curDir = curDir+"\\hibernate.cfg.xml"; System.out.println(curDir); String str = FileUtils.readFileToString(new File(curDir)); //System.out.println(str); Configuration configuration = new Configuration(); configuration.configure(curDir); configuration.getSessionFactoryObserver(); /* configuration.configure(resource); 這個resource不是文件路徑名!! * */