1.我们平时使用的是debug模式,但有时候这种模式使得启动服务时间非常长,如果不存在类级的Bug,可以直接使用Run模式启动服务。通常可以很快的启动了。但下次再启动服务时,eclipse会使用上一次的启动模式,如果不知道这一点,我们就没办法重新使用debug模式启动了。在run模式下,我们在类里的修改不能立即被服务器识别,不能进行全部的调试。要想重新使用debug模式启动,先点窗口,再点视图,再点server,然后在出现的服务器视图里选择debug模式启动即可。
2.hiberate query.setDate('",newDate()),不能使sql进行时分秒级的比较.此时应该使用.setTimeStamp().
3.hibernate由hbm生成数据库表
package com.movo.tv.common.util;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**
* 由类反生成表 |generate tables by pojos.
* @author zlj
*
*/
public class CreateDB {
private static Configuration config;
static{
try {
config=new Configuration().configure();
} catch (HibernateException e) {
e.printStackTrace();
}
}
public static void create(){
SchemaExport se=null;
try {
se=new SchemaExport(config);
se.setOutputFile("E:\\sql.txt");
se.create(true,true);
} catch (HibernateException e) {
e.printStackTrace();
}
}
public static void main(String args[]){
create();
}
}
默认的hibernate.cfg.xml在src文件夹下,至少包括如下内容
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/movo_new</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="com/movo/tv/pojo/hbm/Artcomment.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/City.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Citytrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Comclasstrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Commentcontext.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Compass.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Compassclass.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Compasstrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MArticle.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCategory.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCategorytrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MChArticleSplit.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCharticletrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MChartmoki.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCity.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCitytrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCollection.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCommentcontext.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCountry.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCountrytrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MCustommodel.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MEnArticleSplit.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MEnarticletrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MEnartmoki.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MFriend.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MFriendgrouplink.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MFriendurl.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MFriendurltranse.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MFriengroup.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MGenre.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MGenretranse.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MGroup.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MImagecomments.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MIndexplace.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MJaArticleSplit.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MJaarticletrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MJaartmoki.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MKoArticleSplit.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MKoarticletrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MKoartmoki.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MLatestvisit.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMessagetranse.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusic.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusicBox.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusiccomments.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusicommtran.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusicset.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusicsettrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusicskin.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MMusictranse.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPagececollect.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPagevisttemp.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPagevisttempvist.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPhotoimages.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPhotoset.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPhotosettrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MPhototrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MReceive.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MRecommendBlog.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MReview.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MReviewcontext.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MSendinfo.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MSmallimages.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MSysmessage.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MTag.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MTagtrance.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MTemplate.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/Muserevent.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MUserinfo.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MUsertag.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MUsertrack.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/MUsetranse.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/SUser.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YActivity.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YActivitytrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YAdv.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YAdvtrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YComment.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YCommenttrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YCompanyzhaopin.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YCompanyzhaopintrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YDiscount.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YDiscounttrans.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YKeyword.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YRecommend.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YReport.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YVideo.hbm.xml"/>
<mapping resource="com/movo/tv/pojo/hbm/YVideotrans.hbm.xml"/>
</session-factory>
</hibernate-configuration>