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 primary 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?

Answers


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.


Need Your Help

Checkout project from Google code using Ant error

svn ant google-code svnant

<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />

View All Binds, wxpython

python wxpython wxwidgets wx

Is there a way to view all binds of an object?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.