Some people (like me) prefer to use private variables for persistence. Comment out this line in your OJB.properties file:
PersistentFieldClass=org.apache.ojb.broker.metadata.PersistentFieldDefaultImpl
...and uncomment this one:
PersistentFieldClass=org.apache.ojb.broker.metadata.PersistentFieldPropertyImpl
....and OJB will use the bean setters/getters

Gareth

Mark Horgan wrote:
I have a situation where my date field is built from 3 separate
day/month/year int fields (populated from a form), but the thing is OJB
seems to access the private field rather than the public getter method,
what's up with that?

Mark


<class-descriptor class="ie.dkit.careers.models.form.Appointment"
table="appointments">
	<field-descriptor autoincrement="true" column="a_id" id="1"
jdbc-type="INTEGER" name="id" primarykey="true"/>
	<field-descriptor name="date" column="a_date" id="3" jdbc-type="DATE"/>
</class-descriptor>


public class Appointment extends BaseFormModel {
    	//used in an xmlform in cocoon
	private int dateDay; int dateMonth; int dateYear;

	//kind of redundant but OJB complained when it was missing
	//At the moment it sets the db to 1-1-1970 which is 0 rather than what is
taken from the form
    	private Date date=new Date(0);

	public Date getDate(){
		GregorianCalendar calendar=new
GregorianCalendar(TimeZone.getTimeZone("GMT"));
		calendar.set(dateYear,dateMonth,dateDay);
		return (Date)calendar.getTime();
	}

	public void setDate(Date aDate){
		GregorianCalendar calendar=new
GregorianCalendar(TimeZone.getTimeZone("GMT"));
		calendar.setTime((java.util.Date)aDate);
		dateYear=calendar.get(Calendar.YEAR);
		dateMonth=calendar.get(Calendar.MONTH);
		dateDay=calendar.get(Calendar.DAY_OF_MONTH);
	}


	public void setDateDay(String aDateDay){
      	if (aDateDay.equals(""))
        		dateDay=0;
      	else
        		dateDay=Integer.parseInt(aDateDay);
	}

    	public String getDateDay(){
      	return String.valueOf(dateDay);
    	}

	public void setDateMonth(String aDateMonth){
      	if (aDateMonth.equals(""))
        		dateMonth=0;
      	else
        		dateMonth=Integer.parseInt(aDateMonth);
	}

    public String getDateMonth(){
      return String.valueOf(dateMonth);
    }

	public void setDateYear(String aDateYear){
	      if (aDateYear.equals(""))
      	  dateYear=0;
	      else
      	  dateYear=Integer.parseInt(aDateYear);
	}

    public String getDateYear(){
      return String.valueOf(dateYear);
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
-------------------
Gareth Cronin
Analyst/Programmer
Kiwiplan NZ Ltd
Ph 2727622 x854
-------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to