开发者

Datanucleus changing column names?

开发者 https://www.devze.com 2023-03-30 09:05 出处:网络
I\'ve got a two classes that look like this: @PersistenceCapable(detachable=\"true\") @Inheritance(strategy=InheritanceStrategy.SUBCLASS_TABLE)

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.


Removing the @Inheritence(strategy=Inheritence.COMPLETE_TABLE) seems to have done the trick!

0

精彩评论

暂无评论...
验证码 换一张
取 消