为了开发方便 ,有时候对一些代码的移植很重要,这样可以缩短开发的时间。但是有时候也会遇到不起不期而遇的事情。hibernate映射的表名、类名一样,只是类所对应的包名不一样的情况下,程序很难知道它导入的是哪个包的类,这就需要在配置文件中在包名导入的时候写上这么一句代码
< hibernate-mapping package="com.tct.db.hbm.programs" auto-import="false">
- 1.
避免自动导入,然后在程序编写中 使用该类名时,利用包来指定所对应的类就可以了。
LifeLuckyResult.hbm.xml(表的映射文件)
< ?xml version="1.0"?>
< !DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
< hibernate-mapping package="com.tct.db.hbm.programs" auto-import="false">
< class name="LifeLuckyResult" table="pro_LUCKY_RESULT">
< id name="dnId" column="dn_Id" type="long">
< generator class="sequence">
< param name="sequence">SEQ_TEMP_LUCKY_RESULT_ID< /param>
< /generator>
< /id>
< property name="dcName" column="DC_NAME" type="string" not-null="true" />
< property name="dnLuckycount" column="DN_LUCKYCOUNT" type="long" not-null="true" />
< property name="dnCreatetime" column="DN_CREATETIME" type="timestamp" not-null="true"/>
< property name="dnAllcount" column="DN_ALLCOUNT" type="long" not-null="true"/>
< property name="dnLuckytime" column="DN_LUCKYTIME" type="timestamp" not-null="true"/>
< property name="dntype" column="DN_DNTYPE" type="int" not-null="true"/>
< /class>
< /hibernate-mapping>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
在程序代码编写的过程中编写的hql语句:
例如:
select count(*) from com.tct.db.hbm.programs.LifeLuckyResult
- 1.
这样就解决了Hibernate重复导入的问题。
【编辑推荐】