Whenever you want to control object identity with your own source code, you have to use application identity. This requires also a primary key class beside your business class. This class must fullfil the following requirements:
Sample class Person:
public class Person
{
. . .
private Integer id; // primary key field
private String name; // jdo persistent field
private Integer xyz; // jdo persistent field
...
}
The primary key for class Person could be implemented like this:
// primary key class for class Person
public class PersonKey implements Serializable
{
public Integer id; // primary key field
public PersonKey()
{
}
public PersonKey(String key)
{
id = Integer.parseInt(key);
}
public boolean equals(Object o)
{
if (o != null && o instanceof PersonKey)
{
return id.equals(((PersonKey)o).id);
}
return false;
}
public int hashCode()
{
return id.hashCode();
}
public String toString()
{
return Integer.toString(id);
}
}
To enable application identity the JDO file for the Person looks like this:
<class name="Person" identity-type="application" objectid-class="com.test.PersonKey"> <field name="id" default-fetch-group="true" primary-key="true" /> <field name="name" default-fetch-group="true" /> ... </class>With application identity you have the choice to manage the identity values by hand or automatically via a Signsoft intelliBO ObjectIdGenerator (see also chapter "Automatic Object Id Generation").