既然用hibernate的东东,需要O/R对应,O应该都是必须的吧。
你说表结构一样?那干吗建那么多表呢?
如果真是这样,那也不麻烦:
查询时传递表名,根据表名通过spring来取的实体XXXInfo对象。 public Object QueryInfo(String,username,String userpassword,String userflag,String tableName){
//Object user = ApplicationContext.getBean(tableName);
Object user = null;
String hsql = " from "+tableName+"s where s.username='"+username+"' and s.userpassword='"+userpassword+"'" +
"and s.userflag='"+userflag+"'";
List list = this.getHibernateTemplate().find(hsql);
if(list != null && !list.isEmpty()){
user = list.get(0);
}
return user;
} 然后,取得user对象根据实际情况转化一下,不知道说的对不对。
你说表结构一样?那干吗建那么多表呢?
如果真是这样,那也不麻烦:
查询时传递表名,根据表名通过spring来取的实体XXXInfo对象。 public Object QueryInfo(String,username,String userpassword,String userflag,String tableName){
//Object user = ApplicationContext.getBean(tableName);
Object user = null;
String hsql = " from "+tableName+"s where s.username='"+username+"' and s.userpassword='"+userpassword+"'" +
"and s.userflag='"+userflag+"'";
List list = this.getHibernateTemplate().find(hsql);
if(list != null && !list.isEmpty()){
user = list.get(0);
}
return user;
} 然后,取得user对象根据实际情况转化一下,不知道说的对不对。
public List getSSXSList(String tname){
System.out.println("---getSSXSList is begin---");
String hsql = " from "+tname+" s where s.PHONE not in(select phone from cancelphone) order by TIME desc";
System.out.println("hsql = " + hsql);
List list = this.getHibernateTemplate().find(hsql);
System.out.println("---getSSXSList is end---" );
return list;
}
提示:
---getSSXSList is begin---
hsql = from JTGB_COMMENT s where s.PHONE not in(select phone from cancelphone) order by TIME desc
2008-8-8 10:01:17 com.nl.nxtv.action.NxtvPublicAction ssxs
严重: JTGB_COMMENT is not mapped [ from JTGB_COMMENT s where s.PHONE not in(select phone from cancelphone) order by TIME desc]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: JTGB_COMMENT is not mapped [ from JTGB_COMMENT s where s.PHONE not in(select phone from cancelphone) order by TIME desc]
org.springframework.orm.hibernate3.HibernateQueryException: JTGB_COMMENT is not mapped [ from JTGB_COMMENT s where s.PHONE not in(select phone from cancelphone) order by TIME desc]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: JTGB_COMMENT is not mapped [ from JTGB_COMMENT s where s.PHONE not in(select phone from cancelphone) order by TIME desc]
Caused by: org.hibernate.hql.ast.QuerySyntaxException: JTGB_COMMENT is not mapped [ from JTGB_COMMENT s where s.PHONE not in(select phone from cancelphone) order by TIME desc]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)看来还是要映射,难道没有其他的办法了么,那个高手可以解决一下哈。