views:

85

answers:

1

I have a class like this :

import java.io.*;
import java.util.*;

public class Contact_Info_Entry implements Serializable
{
  public static final long serialVersionUID=26362862L;
  String Contact_Id,First_Name="",Last_Name="",Company_Name="",Branch_Name="",Address_1="",Address_2="",City="",State="",Zip="",Country="",E_Mail="",Phone;
  int I_1,I_2;
  float F_1,F_2;
  boolean B_1,B_2;
  GregorianCalendar Date_1, Date_2;
  Vector<String> A_Vector=new Vector<String>();

  public Contact_Info_Entry() { }

......
}

If I want to translate it to a class for JDO, do I need to define each field by it self or can I do a group at a time ?

For instance do I have to make it like this :

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Contact_Info_Entry implements Serializable
{
  @PrimaryKey
  @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
  private Long id;
  @Persistent
  public static final long serialVersionUID=26362862L;
  @Persistent
  String Contact_Id;
  @Persistent
  String First_Name;
  @Persistent
  String Last_Name;
......
  @Persistent
  int I_1;
  @Persistent
  int I_2;
...
  @Persistent
  float F_1;
...
  @Persistent
  boolean B_1;
  @Persistent
  boolean B_2;
  @Persistent
  GregorianCalendar Date_1;
...
  @Persistent
  Vector<String> A_Vector=new Vector<String>();

  public Contact_Info_Entry() { }

......
}

Or can I do a group at a time like this :

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Contact_Info_Entry implements Serializable
{
  @PrimaryKey
  @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
  private Long id;
  @Persistent
  public static final long serialVersionUID=26362862L;
  @Persistent
  String Contact_Id,First_Name,Last_Name="";
......
  @Persistent
  int I_1=0,I_2=1;
...
  @Persistent
  float F_1;
...
  @Persistent
  boolean B_1,B_2;
  @Persistent
  GregorianCalendar Date_1;
...
  @Persistent
  Vector<String> A_Vector=new Vector<String>();

  public Contact_Info_Entry() { }

......
}

Or can I skip the "@Persistent" all together like this :

import java.io.*;
import java.util.*;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Contact_Info_Entry implements Serializable
{
  public static final long serialVersionUID=26362862L;
  String Contact_Id,First_Name="",Last_Name="",Company_Name="",Branch_Name="",Address_1="",Address_2="",City="",State="",Zip="",Country="",
         E_Mail="",Phone;
  int I_1,I_2;
  float F_1,F_2;
  boolean B_1,B_2;
  GregorianCalendar Date_1, Date_2;
  Vector<String> A_Vector=new Vector<String>();

  public Contact_Info_Entry() { }

......
}

Which are correct ?

Frank

+1  A: 

You do NOT need to annotate every field with @Persistent. The vast majority of types (primitives, their wrappers, String etc etc) are by default persistent. Just write your class as your class ought to be. Read http://www.datanucleus.org/products/accessplatform_1_1/jdo/types.html

You can't persist static fields http://www.datanucleus.org/products/accessplatform_1_1/jdo/fields_properties.html

Google's docs usage of @Persistent on everything is totally misleading

As for declarations of multiple fields on the same line and whether the annotation applies to all, I would assume that the compiler will apply the annotation to all fields on that line, but that is to do with Java and how the compiler implements annotations rather than anything specific to JDO.

DataNucleus
Thanks. I've noticed from the url above, in the SCO types table GregorianCalendar is not persistent by default, so in my example I only need to declear " @Persistent GregorianCalendar Date_1,Date_2;" because all other fields are by default persistent, am I correct ?
Frank
That is correct
DataNucleus