开发者

Spring Roo @Id field not populated in DataOnDemand test

I am working with a web application built on Spring Roo 1.0.2. I have defined an entity that has a primary key PERSONID column as well as several other fields.

@Id
@Column(name = "PERSONID", precision = 10, scale = 0)    
private Long personId;

@Size(max = 50)
@Column(name = "NAME")
@NotNull
private String name;

...

The Roo-managed integration tests contain a function that instantiates a mock object and populates each of the non-Id fields.

public Person PersonDataOnDemand.getNewTransientPerson(int index) {
    Person obj = new Person();    
    obj.setName("name_" + index);

    //set other non-Id fields

    return obj;
}

This function is called from integration tests and subsequently fails as the database table has a not null constraint on the PERSONID column. I have tried explicitly setting the @NotNull annotation on the personId column, but it has no effect. I suspect this has something to do with the fact that PERSONID is a non-autogenerated primar开发者_Python百科y key.

I know I can address this by overriding the integration tests and populating the Id myself, but I would like to avoid this if possible. Does anyone know a way that I can get this field automatically populated in the managed DataOnDemand objects?


Spring Roo gerates it own ID field, in its _entity.aj aspect. So no extra field marked with @ID is needed in the "base"-class. The Roo managed ID field should be populated by Roo's DataOnDemand.

The data base column for the roo managed id is "id" by default. If you need an other colum name (for example to match the database schema) then the column could be specified by the @RooEntity.identifierColumn.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜