我有一个像这样的简单课程:
@DatabaseTable(tableName = "VlpTag")
public class VlpTag implements Serializable {
private static final long serialVersionUID = -4912974444196844860L;
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(foreign = true, columnName = "buid", canBeNull = false, foreignAutoCreate = true, foreignAutoRefresh = true)
private VlpVirtualApp vApp;
@DatabaseField
private long lastUpdated;
@DatabaseField(index=true)
private String tagValue;
@DatabaseField(dataType = DataType.ENUM_INTEGER)
private TagType tagType;
public static enum TagType {
UUID, TAG
};
public VlpTag() {
// needed by ormlite
}
}
然后,如果表不存在,我使用 TableUtils 创建表:
TableUtils.createTableIfNotExists(MySQLConnection.getInstance()
.getConnection(), VlpTag.class);
如果表不存在,则没有问题,虽然表存在,但 ORMLite 会引发异常说索引存在:
java.sql.SQLException: SQL statement failed: CREATE INDEX `VlpTag_tagValue_idx` ON `VlpTag` ( `tagValue` )
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:464)
at com.j256.ormlite.table.TableUtils.doCreateTable(TableUtils.java:440)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:220)
at com.j256.ormlite.table.TableUtils.createTableIfNotExists(TableUtils.java:61)
at com.banctecmtl.ca.vlp.controller.listvmupdater.DatabaseUpdater.<init>(DatabaseUpdater.java:47)
at com.banctecmtl.ca.vlp.controller.listvmupdater.ListVMUpdater.<init>(ListVMUpdater.java:42)
at com.banctecmtl.ca.vlp.controller.VlpController.<init>(VlpController.java:75)
at com.banctecmtl.ca.vlp.view.webview.server.VlpControllerServiceImpl.init(VlpControllerServiceImpl.java:32)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate key name 'VlpTag_tagValue_idx'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)
at com.j256.ormlite.jdbc.JdbcCompiledStatement.runExecute(JdbcCompiledStatement.java:62)
at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:458)
... 29 more
此错误已在错误列表中报告,我想知道它是否已解决,因为我有同样的问题。我使用 MYSQL 和ormlite-core-4.33.jar
.
我在这里做错了什么,还是有问题?
谢谢