首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

MyEclipse5.5自动映射出现的疑惑,该怎么处理

2012-02-29 
MyEclipse5.5自动映射出现的疑惑以前使用MyEclipse4.1生成Hibernate映射文件的时候,只生成一个POJO文件例

MyEclipse5.5自动映射出现的疑惑
以前使用MyEclipse4.1生成Hibernate映射文件的时候,只生成一个POJO文件
例如   对应   user表中有id   name   password   两个字段   id为自动编号
生成映射文件user.hbm.xml为
[code]     <hibernate-mapping>    
                    <class   name= "tuser.Tuser "   table= "t_user ">    
                                    <id   name= "id ">    
                                            <generator   class= "increment "/>    
                                    </id>    
                                    <property   name= "name "/>    
                                    <property   name= "password "/>    
                    </class>    
    </hibernate-mapping> [/code]
而使用MyEclipse5.5后映射文件变为了,貌似使用了主键的方式进行映射
[code]     <hibernate-mapping>    
<class   name= "tuser.Tuser "   table= "t_user "   schema= "dbo "   catalog= "HAHANews ">
<composite-id   name= "id "   class= "t_user.TUserId ">
<key-property   name= "id "   type= "java.lang.Integer ">
<column   name= "ID "   />
</key-property>
<key-property   name= "name "   type= "sring ">
<column   name= "name "   length= "10 "   />
</key-property>
<key-property   name= "password "   type= "sring ">
<column   name= "password "   length= "10 "   />
</key-property>
                                </composite-id>
                    </class>    
    </hibernate-mapping> [/code]
并且生成两个POJO文件(可能不这样称呼,但我是这样理解的   呵呵)
User.java为
================================
[code]public   class   Tuser   implements   java.io.Serializable   {
private   TuserId   id;
public   Tuser   ()   {
}
public   Tuser   (TuserId   id)   {
this.id   =   id;
}
public   TuserId   getId()   {
return   this.id;
}
public   void   setId(TuserId   id)   {
this.id   =   id;
}
}[/code]


UserId.java为
================================
[code]public   class   TuserId   implements   java.io.Serializable   {
private   Integer   id;
private   String   name;
private   String   password;
…………省略get和set方法…………[/code]




MyEclipse5.5还自动生成了DAO文件,因为我使用了Spring,DAO文件如下
UserDAO.java中一个方法为
================================
[code]public   List   findByExample(Tuser   instance)   {
log.debug( "finding   Tuser   instance   by   example ");
try   {
List   results   =   getHibernateTemplate().findByExample(instance);
log.debug( "find   by   example   successful,   result   size:   "
+   results.size());
return   results;
}   catch   (RuntimeException   re)   {
log.error( "find   by   example   failed ",   re);
throw   re;
}
}[/code]

为此我在Action使用了一下语句条用该方法
LoginAction.java
================================
[code]TYhId   tuserid   =   new   TuserId();
tuserid   .setName(loginForm.getString( "name "));
tuserid   .setPassword(loginForm.getString( "password "));
System.out.println( "name: "   +   tuserid.getName());
System.out.println( "paswword: "   +   tuserid.getPassword());
System.out.println(this.tyhDAO.findByExample(new   Tuser(tuserid)).size());[/code]

最终Action运行正常,显示的结果也说明tuserid中已经赋值,但在print   Tuser.size的时候显示的是数据库中所有记录的总数,并且在控制台中看到对应的SQL语句最后为   ....where   (1=1)

请问如何使用MyEclipse5.5只生成一个POJO文件,如何修改Action中的程序满足验证的需要

已查过N多资料   还是无解   万分感谢   呵呵

[解决办法]
关注
[解决办法]
Eclipse的反向工程一直都有问题
BEA的workshop做这个挺好的

不大懂 帮你顶一下

热点排行