NutzCN Logo
问答 关于主键名重写父类属性后主键无效的问题
发布于 2921天前 作者 qq_6c186ef5 2250 次浏览 复制 上一个帖子 下一个帖子
标签: dao 映射
public class Po implements Serializable{
	//通用id主键
	@Id
	private long id;

	public long getId() {
		return id;
	}
        public void getId(long id) {
		this.id = id;
	}
}
public class MyPo extends Po{
      @Id
      @Column("msgId")
      private long id;
      //set/get....
}

在自雷中继承父类po之后,要重写父类主键id并且在数据库中主键叫msgId,按照我以上所写的为什么会报错了

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 列名 'id' 无效。
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:616)
	at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:199)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:45)
	... 39 more
5 回复

把子类的id改名

直接改名为msgId就可用了?

但@Id会重复

再抽象一个超类,然后分别继承

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