NutzCN Logo
问答 nutzdao+druid使用非数据库实体VO接收返回的对象一直报“Table ‘xxxxx’ doesn't exist”
发布于 2993天前 作者 panshaobinSB 3842 次浏览 复制 上一个帖子 下一个帖子
标签:

nutzdao+druid使用非数据库实体VO接收返回的对象一直报“Table ‘xxxxx’ doesn't exist”


sql.setCallback(Sqls.callback.entities()) ; //返回一组对象 Entity<T> entity = dao.getEntity(clazz) ; sql.setEntity(entity) ; dao.execute(sql) ;

dao.getEntity(clazz) ;时报错

报错信息如下:

- No @Table found, fallback to use table name='tm_user_v_o' for type 'com.xxxx.TmUserVO'
[20161012 13:19:35.809] {Thread-25} <ERROR> druid.sql.Statement: {conn-10002, stmt-20003} execute error. SELECT * FROM tm_user_v_o LIMIT 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'whfq_tester.tm_user_v_o' doesn't exist
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_73]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_73]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_73]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_73]
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569) ~[mysql-connector-java-5.1.16.jar:na]
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1510) ~[mysql-connector-java-5.1.16.jar:na]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2363) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterAdapter.statement_executeQuery(FilterAdapter.java:2481) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeQuery(FilterEventAdapter.java:302) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2360) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterAdapter.statement_executeQuery(FilterAdapter.java:2481) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeQuery(FilterEventAdapter.java:302) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2360) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.wall.WallFilter.statement_executeQuery(WallFilter.java:498) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2360) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterAdapter.statement_executeQuery(FilterAdapter.java:2481) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeQuery(FilterEventAdapter.java:302) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2360) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeQuery(StatementProxyImpl.java:211) [druid-1.0.15.jar:1.0.15]
	at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:143) [druid-1.0.15.jar:1.0.15]
	at org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:75) [nutz-1.b.52.jar:na]
	at org.nutz.dao.impl.entity.AnnotationEntityMaker._checkupEntityFieldsWithDatabase(AnnotationEntityMaker.java:534) [nutz-1.b.52.jar:na]
	at org.nutz.dao.impl.entity.AnnotationEntityMaker.make(AnnotationEntityMaker.java:277) [nutz-1.b.52.jar:na]
	at org.nutz.dao.impl.EntityHolder.getEntity(EntityHolder.java:65) [nutz-1.b.52.jar:na]
	at org.nutz.dao.impl.NutDao.getEntity(NutDao.java:638) [nutz-1.b.52.jar:na]

PS:用其他连接池不会报错,只会提示:- No @Table found, fallback to use table name='tm_user_v_o' for type 'com.xxxx.TmUserVO'

5 回复

那就不应该用entities哦, 改成用Record

			sql.setCallback(Sqls.callback.records()) ;	//返回一组对象		
			dao.execute(sql) ;
			List<T> list = new ArrayList<T>();
			for (Record re : sql.getList(Record.class))
                list.add(re.toPojo(klass));
		    return list;

@wendal 上面的代码解决了报错的问题,但是re.toPojo(klass)又有新的问题,Record这个map默认会把驼峰的字符串全部变成小写,而我的VO是驼峰命名属性的,所以不能转换,有没有啥好的解决办法?

换成maps回调

	sql.setCallback(Sqls.callback.maps()) ;	//返回一组对象		
			dao.execute(sql) ;
			List<T> list = new ArrayList<T>();
			for (Map re : sql.getList(Map.class))
                list.add(Lang.map2object(.....));
		    return list;

添加回复
请先登陆
回到顶部