About Question enthuware.oce-jpad.v6.2.559 :

Moderator: admin

Post Reply
johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

About Question enthuware.oce-jpad.v6.2.559 :

Post by johnlong » Sat Dec 24, 2016 1:52 pm

If a property based access is chosen for an entity class, the names of the fields do not have to correspond to the method names.
Could you please explain how names of the field will not correspond to method names (will not correspond to JavaBean conventions).

admin
Site Admin
Posts: 8304
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by admin » Sun Dec 25, 2016 1:00 pm

Code: Select all

private int xxx;
public int getA(){
 return xxx;
}
Javabeans convention does not require field name to be same as the property name.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by johnlong » Sun Dec 25, 2016 6:29 pm

field is "name"
setter and getter do not have to be "getName" and "setName"?
I think Javabeans would require exact naming as above, but JPA specifications are not required to be compliant. Correct?

admin
Site Admin
Posts: 8304
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by admin » Mon Dec 26, 2016 12:47 am

johnlong wrote:field is "name"
setter and getter do not have to be "getName" and "setName"?
Correct.
I think Javabeans would require exact naming as above, but JPA specifications are not required to be compliant. Correct?
Incorrect. Javabeans has no such rule on the naming of the field.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by johnlong » Wed Dec 28, 2016 7:50 am

You mean it is convention, but it is not recommendation?

admin
Site Admin
Posts: 8304
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by admin » Thu Dec 29, 2016 2:06 am

Javabeans conventions are conventions. And they don't impose any constraint on the name of the variable. So no, it is not an official convention. It is, however, considered a good programming practice (or recommendation, if you want to call it that:) ) to keep your variable name in line with the getter/setter names to avoid confusion.

Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by johnlong » Thu Dec 29, 2016 11:41 am

JPA Specification 2.1 (Section 2.2) says :
It is required that the entity class follow the method signature conventions for JavaBeans read/write properties (as defined by the JavaBeans Introspector class) for persistent properties when property access is used.

In this case, for every persistent property property of type T of the entity, there is a getter method, getProperty, and setter method setProperty. For boolean properties, isProperty may be used as an alternative name for the getter method.
For single-valued persistent properties, these method signatures are:
• T getProperty()
• void setProperty(T t)

admin
Site Admin
Posts: 8304
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by admin » Thu Dec 29, 2016 12:42 pm

Not sure what is your point but nowhere does it talk about the field/variable name.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by johnlong » Thu Dec 29, 2016 2:54 pm

What about this sentence :

In this case, for every persistent property property of type T of the entity, there is a getter method, getProperty, and setter method setProperty.

admin
Site Admin
Posts: 8304
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by admin » Thu Dec 29, 2016 10:15 pm

Yes, but property != variable/field.

As soon as a class gets a getX (and setX, if it is a mutable property), it is said to have a property named x. Irrespective of whether it has a variable/field named x or not.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by johnlong » Wed Jan 04, 2017 11:04 am

If property is not field, then what is it?

admin
Site Admin
Posts: 8304
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.559 :

Post by admin » Wed Jan 04, 2017 11:25 am

If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests