Datanucleus 更改列名称?
我有两个类,如下所示:
@PersistenceCapable(detachable="true")
@Inheritance(strategy=InheritanceStrategy.SUBCLASS_TABLE)
public abstract class BasicReference implements Serializable {
private static final long serialVersionUID = 1L;
@Persistent(column="last_modified")
private Date lastModified;
public abstract String getTitle();
public abstract void setTitle(String title);
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}
@PersistenceCapable(table="X_MYENTRY",detachable="true")
@Inheritence(strategy=Inheritence.COMPLETE_TABLE)
public class MyEntry extends BasicReference {
private static final long serialVersionUID = 1L;
@Persistent(column="MYENTRY_ID")
private Integer id;
@Persistent
private String title;
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
public Integer getId() {
return id;
}
}
我的数据库模式如下所示:
CREATE TABLE X_MYENTRY (
MYENTRY_ID int identity(1,1),
TITLE varchar(64),
lastModified datetime
)
我有任意数量的这些 X_ 表,每个表都有细微的变化,主要是在某些字段的允许长度方面。
现在,当我尝试从持久性管理器进行查询时,收到一条错误,指出无法找到 X_MYENTRY_ID 列。即使我已将列名称指定为 MYENTRY_ID。
此时我什至并不真正担心 @PrimaryKey,我只是希望能够获取对象。
我尝试更改注释以使用各种值。除 MYENTRY_ID 之外的任何内容都会给我一个错误,指出指定的列不存在。但是,如果我使用 MYENTRY_ID,我会得到 X_MYENTRY_ID 不存在。
我尝试更改数据库中的列,只是作为测试,但出现了不同的错误: org.datanucleus.exceptions.NucleusUserException:表“X_MYENTRY”中存在列“X_MYENTRY_ID”,并且元数据无效。现有列是“
我在 SQL Server 中的表名为 X_REFERENCE,主键是 REFERENCE_ID int Identity(1,1)。此时我什至不担心 @PrimaryKey,我只是希望能够读取但是,当我尝试通过 PersistenceManager 查询此数据时,如果我将注释中的列名称更改为其他名称,则会在 X_REFERENCE_ID 列上收到 SQL 错误。 (“YREFERENCE_ID”),它似乎会接受并尊重它,但是“REFERENCE_ID”似乎会自动替换为“X_REFERENCE_ID”。如果我将测试数据库中的列重命名为 X_REFERENCE_ID,它会引发 REFERENCE_ID 无法执行的错误。找到
任何使这些 id 正常工作的帮助将不胜感激。
I've got a two classes that look like this:
@PersistenceCapable(detachable="true")
@Inheritance(strategy=InheritanceStrategy.SUBCLASS_TABLE)
public abstract class BasicReference implements Serializable {
private static final long serialVersionUID = 1L;
@Persistent(column="last_modified")
private Date lastModified;
public abstract String getTitle();
public abstract void setTitle(String title);
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}
@PersistenceCapable(table="X_MYENTRY",detachable="true")
@Inheritence(strategy=Inheritence.COMPLETE_TABLE)
public class MyEntry extends BasicReference {
private static final long serialVersionUID = 1L;
@Persistent(column="MYENTRY_ID")
private Integer id;
@Persistent
private String title;
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
public Integer getId() {
return id;
}
}
My database schema looks like this:
CREATE TABLE X_MYENTRY (
MYENTRY_ID int identity(1,1),
TITLE varchar(64),
lastModified datetime
)
I have any number of these X_ tables, each with slight variations, mostly in the permitted length of some of the fields.
Now, when I try an query from the persistence manager, I get an error that the column X_MYENTRY_ID could not be found. Even though I've specified the column name as MYENTRY_ID.
I'm not even really worried about @PrimaryKey at this point, I just want to be able to get the objects in.
I've tried changing the annotations to use various values. Anything other than MYENTRY_ID, will give me an error that the specified column doesn't exist. However if I use MYENTRY_ID, I get the X_MYENTRY_ID does not exist.
I've tried changing the column in the database, just as a test, and I get a different error:
org.datanucleus.exceptions.NucleusUserException: The column "X_MYENTRY_ID" exists in table "X_MYENTRY" and has invalid metadata. The existing column is "
My table in SQL Server is named X_REFERENCE, and the primary key is REFERENCE_ID int identity(1,1). I'm not even worried about @PrimaryKey at this point, I just want to be able to read the data in. However, when ever I try and query this via the PersistenceManager, I get a SQL error on column X_REFERENCE_ID. If I change the column name in the annotations to something else ("YREFERENCE_ID"), it appears to pickup on that and honor it. But "REFERENCE_ID" seems to be automagically replaced with "X_REFERENCE_ID". If I rename the column in my test database to X_REFERENCE_ID, it throws an error that REFERENCE_ID could not be found!
Any assistance with getting these id's to work would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除 @Inheritence(strategy=Inheritence.COMPLETE_TABLE) 似乎已经成功了!
Removing the @Inheritence(strategy=Inheritence.COMPLETE_TABLE) seems to have done the trick!