You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Erik Bengtson <er...@jpox.org> on 2007/03/14 10:47:55 UTC

Persistent properties for classes

Hi,

We are implementing persistent properties, and I have some questions.

Question 1:
------------------
Take this example:

<class name="Person">
<field name="name"/>
<property name="birth"/>
</class>

class Person
{
   String name;
   String _birth;

   public Date getBirth()
   {
      return this._birth;
   }

   public void setBirth(Date birth)
   {
      this._birth = birth;
   }
}

Is it allowed to have mixed persistent fields and persistent properties in same
Class or Super Classes?

In JPA, this is explicitly unspecified.

IMO it should not be allowed to avoid user errors (possibly overriding values or
persisting twice the same information).

Question 2:
------------------
Take this example:

<class name="Person">
<property name="name"/>
<property name="birth"/>
</class>

class Person
{
   String _name;
   String _birth;

   public String getName()
   {
      return this._name;
   }

   public void setString(String name)
   {
      this._name = name;
   }
   public Date getBirth()
   {
      return this._birth;
   }

   public void setBirth(Date birth)
   {
      this._birth = birth;
   }
}

By default, _name and _birth would have persistence modifier = persistent. In
this case we are using persistent properties, does the default persistence
modifier for fields changes to transient?

Question 3:
------------------
Take this example:

<class name="Person">
<property name="name"/>
<property name="birth"/>
</class>

class Person
{
   String _name;
   String _birth;

   public String getName()
   {
      return this._name;
   }

   public void setString(String name)
   {
      this._name = name;
   }
   public Date getBirth()
   {
      throw new UnbornException();
   }

   public void setBirth(Date birth)
   {
      this._birth = birth;
   }
}

If an exception is raised from the getter/setter, what should be done by the
implementation?

In JPA, there is an automatic rollback.

Regards,

Erik Bengtson

Re: Persistent properties for classes

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Erik,

We should be able to discuss this at Friday's conference call.

On Mar 14, 2007, at 2:47 AM, Erik Bengtson wrote:

> Hi,
>
> We are implementing persistent properties, and I have some questions.
>
> Question 1:
> ------------------
> Take this example:
>
> <class name="Person">
> <field name="name"/>
> <property name="birth"/>
> </class>
>
> class Person
> {
>    String name;
>    String _birth;
>
>    public Date getBirth()
>    {
>       return this._birth;
>    }
>
>    public void setBirth(Date birth)
>    {
>       this._birth = birth;
>    }
> }
>
> Is it allowed to have mixed persistent fields and persistent  
> properties in same
> Class or Super Classes?
>
> In JPA, this is explicitly unspecified.

Well, not really. From 2.1.1, .A single access type (field or  
property access) applies  to an entity hierarchy.

>
> IMO it should not be allowed to avoid user errors (possibly  
> overriding values or
> persisting twice the same information).

But I don't see the issue with allowing implicit field persistence  
(since JDO 1.0) or explicit property persistence.

>
> Question 2:
> ------------------
> Take this example:
>
> <class name="Person">
> <property name="name"/>
> <property name="birth"/>
> </class>
>
> class Person
> {
>    String _name;
>    String _birth;
>
>    public String getName()
>    {
>       return this._name;
>    }
>
>    public void setString(String name)
>    {
>       this._name = name;
>    }
>    public Date getBirth()
>    {
>       return this._birth;
>    }
>
>    public void setBirth(Date birth)
>    {
>       this._birth = birth;
>    }
> }
>
> By default, _name and _birth would have persistence modifier =  
> persistent. In
> this case we are using persistent properties, does the default  
> persistence
> modifier for fields changes to transient?

Yes. Field names must not be the same as property names. If a  
property is explicitly declared to be persistent, the corresponding  
field must not be persistent. There are rules for determining whether  
fields are persistent; see 18.15 for default persistence-modifier for  
fields. There is no such treatment for properties.
>
> Question 3:
> ------------------
> Take this example:
>
> <class name="Person">
> <property name="name"/>
> <property name="birth"/>
> </class>
>
> class Person
> {
>    String _name;
>    String _birth;
>
>    public String getName()
>    {
>       return this._name;
>    }
>
>    public void setString(String name)
>    {
>       this._name = name;
>    }
>    public Date getBirth()
>    {
>       throw new UnbornException();
>    }
>
>    public void setBirth(Date birth)
>    {
>       this._birth = birth;
>    }
> }
>
> If an exception is raised from the getter/setter, what should be  
> done by the
> implementation?
>
> In JPA, there is an automatic rollback.

I guess this is not specified in JDO. I'd like to see this generate a  
StupidUserException but not set the RollbackRequired flag. Not every  
exception should cause a rollback.

Craig
>
> Regards,
>
> Erik Bengtson

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Persistent properties for classes

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Bin,

Thanks for taking time to reply.

My question is whether we should permit both a persistent field and a  
persistent property to have the same name. I think that the answer is  
no. I'm not sure if this is also your position.

In your example, referring to "${user.name}", should you get the  
value of the field called name, or get the result of getName()? I  
believe that the specification of EL requires a property, i.e. getName 
().

And in JDOQL, if you have a persistent property called name, then  
name == "Mike" gives you the right result.

It's really up to the user whether to use persistent properties or  
persistent fields. Your examples can work with either properties or  
fields, but the results are ambiguous if you have both persistent  
field "name" and persistent property "name".

Craig

On Mar 15, 2007, at 7:55 PM, Bin Sun wrote:

> Hi!
>
>     I strongly oppose to using a different field name
> for a property.
>
>     For a webapp, we may use a JDO javabean like this:
> "${user.name}", and we also frequently need to do
> JDOQL like this: "name=='Mike'".  Keeping field names
> the same as property names can reduce much confusion
> for coders. This is a basic rule for my development.
>
>     How do others think?
>
>
> --- Erik Bengtson <er...@jpox.org> wrote:
>
>> Hi,
>>
>> We are implementing persistent properties, and I
>> have some questions.
>>
>> Question 1:
>> ------------------
>> Take this example:
>>
>> <class name="Person">
>> <field name="name"/>
>> <property name="birth"/>
>> </class>
>>
>> class Person
>> {
>>    String name;
>>    String _birth;
>>
>>    public Date getBirth()
>>    {
>>       return this._birth;
>>    }
>>
>>    public void setBirth(Date birth)
>>    {
>>       this._birth = birth;
>>    }
>> }
>>
>> Is it allowed to have mixed persistent fields and
>> persistent properties in same
>> Class or Super Classes?
>>
>> In JPA, this is explicitly unspecified.
>>
>> IMO it should not be allowed to avoid user errors
>> (possibly overriding values or
>> persisting twice the same information).
>>
>> Question 2:
>> ------------------
>> Take this example:
>>
>> <class name="Person">
>> <property name="name"/>
>> <property name="birth"/>
>> </class>
>>
>> class Person
>> {
>>    String _name;
>>    String _birth;
>>
>>    public String getName()
>>    {
>>       return this._name;
>>    }
>>
>>    public void setString(String name)
>>    {
>>       this._name = name;
>>    }
>>    public Date getBirth()
>>    {
>>       return this._birth;
>>    }
>>
>>    public void setBirth(Date birth)
>>    {
>>       this._birth = birth;
>>    }
>> }
>>
>> By default, _name and _birth would have persistence
>> modifier = persistent. In
>> this case we are using persistent properties, does
>> the default persistence
>> modifier for fields changes to transient?
>>
>> Question 3:
>> ------------------
>> Take this example:
>>
>> <class name="Person">
>> <property name="name"/>
>> <property name="birth"/>
>> </class>
>>
>> class Person
>> {
>>    String _name;
>>    String _birth;
>>
>>    public String getName()
>>    {
>>       return this._name;
>>    }
>>
>>    public void setString(String name)
>>    {
>>       this._name = name;
>>    }
>>    public Date getBirth()
>>    {
>>       throw new UnbornException();
>>    }
>>
>>    public void setBirth(Date birth)
>>    {
>>       this._birth = birth;
>>    }
>> }
>>
>> If an exception is raised from the getter/setter,
>> what should be done by the
>> implementation?
>>
>> In JPA, there is an automatic rollback.
>>
>> Regards,
>>
>> Erik Bengtson
>>
>
>
>
>
> ______________________________________________________________________ 
> ______________
> Don't pick lemons.
> See all the new 2007 cars at Yahoo! Autos.
> http://autos.yahoo.com/new_cars.html

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Persistent properties for classes

Posted by Bin Sun <su...@yahoo.com>.
Hi!

    I strongly oppose to using a different field name
for a property.

    For a webapp, we may use a JDO javabean like this:
"${user.name}", and we also frequently need to do
JDOQL like this: "name=='Mike'".  Keeping field names
the same as property names can reduce much confusion
for coders. This is a basic rule for my development.

    How do others think?


--- Erik Bengtson <er...@jpox.org> wrote:

> Hi,
> 
> We are implementing persistent properties, and I
> have some questions.
> 
> Question 1:
> ------------------
> Take this example:
> 
> <class name="Person">
> <field name="name"/>
> <property name="birth"/>
> </class>
> 
> class Person
> {
>    String name;
>    String _birth;
> 
>    public Date getBirth()
>    {
>       return this._birth;
>    }
> 
>    public void setBirth(Date birth)
>    {
>       this._birth = birth;
>    }
> }
> 
> Is it allowed to have mixed persistent fields and
> persistent properties in same
> Class or Super Classes?
> 
> In JPA, this is explicitly unspecified.
> 
> IMO it should not be allowed to avoid user errors
> (possibly overriding values or
> persisting twice the same information).
> 
> Question 2:
> ------------------
> Take this example:
> 
> <class name="Person">
> <property name="name"/>
> <property name="birth"/>
> </class>
> 
> class Person
> {
>    String _name;
>    String _birth;
> 
>    public String getName()
>    {
>       return this._name;
>    }
> 
>    public void setString(String name)
>    {
>       this._name = name;
>    }
>    public Date getBirth()
>    {
>       return this._birth;
>    }
> 
>    public void setBirth(Date birth)
>    {
>       this._birth = birth;
>    }
> }
> 
> By default, _name and _birth would have persistence
> modifier = persistent. In
> this case we are using persistent properties, does
> the default persistence
> modifier for fields changes to transient?
> 
> Question 3:
> ------------------
> Take this example:
> 
> <class name="Person">
> <property name="name"/>
> <property name="birth"/>
> </class>
> 
> class Person
> {
>    String _name;
>    String _birth;
> 
>    public String getName()
>    {
>       return this._name;
>    }
> 
>    public void setString(String name)
>    {
>       this._name = name;
>    }
>    public Date getBirth()
>    {
>       throw new UnbornException();
>    }
> 
>    public void setBirth(Date birth)
>    {
>       this._birth = birth;
>    }
> }
> 
> If an exception is raised from the getter/setter,
> what should be done by the
> implementation?
> 
> In JPA, there is an automatic rollback.
> 
> Regards,
> 
> Erik Bengtson
> 



 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html