NutzCN Logo
问答 Oracle 更新表结构报错
发布于 2956天前 作者 qq_895c9d88 1638 次浏览 复制 上一个帖子 下一个帖子
标签:

实体类,新增的organizations,factorys:

@Table("system_user")
@TableIndexes({ @Index(name = "user_name", fields = { "username" }, unique = true) })
@View("v_system_user")
public class User{
	@Column
	@ColDefine(type = ColType.VARCHAR, width = 255)
	private String organizations;

	@Column
	@ColDefine(type = ColType.VARCHAR, width = 255)
	private String factorys;
}

报错日记:

2016-10-18 16:21:06,464 [INFO][org.nutz.dao.util.Daos] - add column[organizations] to table[system_user]
2016-10-18 16:21:06,473 [INFO][org.nutz.dao.util.Daos] - add column[factorys] to table[system_user]
2016-10-18 16:21:06,485 [DEBUG][org.nutz.plugins.cache.dao.CachedNutDaoExecutor] - parser SQL sql, skip cache detect!! SQL=ALTER TABLE  ADD organizations VARCHAR2(255);
2016-10-18 16:21:06,486 [DEBUG][org.nutz.dao.impl.sql.run.NutDaoExecutor] - ALTER TABLE  ADD organizations VARCHAR2(255);
2016-10-18 16:21:06,493 [DEBUG][org.nutz.dao.impl.sql.run.NutDaoExecutor] - SQLException
java.sql.SQLSyntaxErrorException: ORA-00903: 表名无效

	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
	at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:195)
	at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1036)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
	at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1916)
	at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1878)
	at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:318)
	at com.alibaba.druid.filter.FilterChainImpl.statement_execute(FilterChainImpl.java:2489)
	at com.alibaba.druid.filter.FilterAdapter.statement_execute(FilterAdapter.java:2451)
	at com.alibaba.druid.filter.FilterEventAdapter.statement_execute(FilterEventAdapter.java:188)
	at com.alibaba.druid.filter.FilterChainImpl.statement_execute(FilterChainImpl.java:2487)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.execute(StatementProxyImpl.java:137)
	at com.alibaba.druid.pool.DruidPooledStatement.execute(DruidPooledStatement.java:421)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:317)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:50)
	at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:89)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:264)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:64)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:219)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:197)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:967)
	at org.nutz.dao.util.Daos.migration(Daos.java:703)
	at org.nutz.dao.util.Daos.migration(Daos.java:744)
	at schedule.go.MvcSetup.init(MvcSetup.java:49)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:270)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:119)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4841)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5535)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
2016-10-18 16:21:06,496 [ERROR][org.nutz.mvc.impl.NutLoading] - Error happend during start serivce!
org.nutz.dao.DaoException: !Nutz SQL Error: 'ALTER TABLE  ADD organizations VARCHAR2(255);'
PreparedStatement: 
'ALTER TABLE  ADD organizations VARCHAR2(255);'
CaseMessage=ORA-00903: 表名无效

	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:97)
	at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:89)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:264)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:64)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:219)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:197)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:967)
	at org.nutz.dao.util.Daos.migration(Daos.java:703)
	at org.nutz.dao.util.Daos.migration(Daos.java:744)
	at schedule.go.MvcSetup.init(MvcSetup.java:49)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:270)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:119)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4841)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5535)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00903: 表名无效

跟踪问题:
Daos类,public static void migration(Dao dao, final Class<?> klass, final boolean add, final boolean del, Object tableName)方法

ResultSetMetaData meta = null;
 try {
 // 获取数据库元信息
 stat = conn.createStatement();
 rs = stat.executeQuery("select * from " + en.getTableName() + " where 1 != 1");
 meta = rs.getMetaData();

          Set<String> columnNames = new HashSet<String>();
          int columnCount = meta.getColumnCount();
          for (int i = 1; i <= columnCount; i++) {
              columnNames.add(meta.getColumnName(i).toLowerCase());
          }
          for (MappingField mf : en.getMappingFields()) {
              if (mf.isReadonly())
                 continue;
              String colName = mf.getColumnName();
              if (columnNames.contains(colName.toLowerCase())) {
                 columnNames.remove(colName.toLowerCase());
                 continue;
              }
              if (add) {
                 log.infof("add column[%s] to table[%s]", mf.getColumnName(), en.getTableName());
                 StringBuilder sb = new StringBuilder("ALTER TABLE ");
                 sb.append(meta.getTableName(1)).append(" ADD ");
                 if (sqlAddNeedColumn)
                   sb.append("COLUMN ");
                 sb.append(colName).append(" ").append(expert.evalFieldType(mf));
                 if (mf.isUnsigned()) {
                   sb.append(" UNSIGNED");
                 }
                 if (mf.isNotNull()) {
                   sb.append(" NOT NULL");
                 }
                 if (mf.getColumnType() == ColType.TIMESTAMP) {
                   if (mf.hasDefaultValue()) {
                    sb.append(" ").append(mf.getDefaultValue(null).replaceAll("@", "@@"));
                   } else {
                    if (mf.isNotNull()) {
                        sb.append(" DEFAULT 0");
                    } else {
                        sb.append(" NULL DEFAULT NULL");
                    }
                   }
                 } else {
                   if (mf.hasDefaultValue())
                    sb.append(" DEFAULT '").append(mf.getDefaultValue(null).replaceAll("@", "@@")).append("'");
                 }
                 if (mf.hasColumnComment() && isCanComment) {
                   sb.append(" COMMENT '").append(mf.getColumnComment()).append("'");
                 }
                 sb.append(';');
                 Sql sql = Sqls.create(sb.toString());
                 sqls.add(sql);
              }
          }
          if (del) {
              for (String colName : columnNames) {
                 log.infof("del column[%s] from table[%s]", colName, en.getTableName());
                 Sql sql = Sqls.create("ALTER table $table DROP column $name");
                 sql.vars().set("table", en.getTableName());
                 sql.vars().set("name", colName);
                 sqls.add(sql);
              }
          }
         } catch (SQLException e) {
          if (log.isDebugEnabled())
              log.debugf("migration Table '%s' fail!", en.getTableName(), e);
         }

其中meta.getTableName(1)获取表名为空,而 en.getTableName()能获取代码中的表名

2 回复

1.r.58是fix了的

@wendal
哦哦,现在就差https://nutz.cn/yvr/t/pjil8oud60j58rtmkc56ss1vjr问题,就可以升级58了

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