Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubts about PK rules and BM in entity beans

 
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.
 
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 )
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic