• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Doubts about PK rules and BM in entity beans

 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The rules for the primary key are:

1) It must be Serializable and public (ok)
2) If the PK matches a single virtual field declared in the EB, we can define it, together with its class, in the DD (ok)
3) If the PK is composed by more than one virtual field, we want to create a custom compound key class (ok)
4) A compound key class fields must be declared as virtual fields in the entity bean class, [and the entity bean class must have public accessors for these]

Between brackets is the part that gives me troubles: would it be enough to have only the abstract getter methods in the EB, for the PK class to be valid?

Although it's well specified in the HF that an EB class SHOULD declare also business methods in order to get/set persistent field values (the given reason was - encapsulation), I don't understand why. I mean, if the getters/setters method would have logic (i.e. for validation) I would agree in declaring custom business methods to access/set persistent fields value, but otherwise I can't see why IT'S a BAD IDEA to have only public abstact getters and setters.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Although it's well specified in the HF that an EB class SHOULD declare also business methods in order to get/set persistent field values (the given reason was - encapsulation), I don't understand why. I mean, if the getters/setters method would have logic (i.e. for validation) I would agree in declaring custom business methods to access/set persistent fields value, but otherwise I can't see why IT'S a BAD IDEA to have only public abstact getters and setters.



Well I think it is the same case as Instance variables. We all know that we are supposed to mark our instance variables private (which means its transparent to other classes), and have getters and setters to access them. Thus, they are forced to go through getters and setters. We sure could have made it public and have no getters and setters, but now, you have no clue what values the instance variable might get.

Now, suppose the virtual field as follow:

public abstract void setLast (String last);

If we just exposed this to our client, how can we make a restriction to only allow the client to setLast is from "M-Z"

By using setters, we could have achieved this. Even if we don't have any restrictions to our setters, we should always have getters/setters for the same reason as instance variables. (Hope that example didnt violate any of EJB Spec )
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic