Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubts about PK rules and BM in entity beans

 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • 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.
 
Dan T
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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 )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic