Sponsered Links
Categories
Sponsered Links

POJO implementation of the User class

 

  1. Hibernate doesn’t require that persistent classes implement Serializable. However, when objects are stored in an HttpSession or passed by value using RMI, serialization is necessary. (This is very likely to happen in a Hibernate application.)
  2. Unlike the JavaBeans specification, which requires no specific constructor, Hibernate requires a constructor with no arguments for every persistent class. Hibernate instantiates persistent classes using Constructor.newInstance(), a feature of the Java reflection API. The constructor may be non-public, but it should be at least package-visible if runtime-generated proxies will be used for performance optimization.
  3. The properties of the POJO implement the attributes of our business entities—for example, the username of User. Properties are usually implemented as instance variables, together with property accessor methods: a method for retrieving the value of the instance variable and a method for changing its value. These methods are known as the getter and setter, respectively. Our example POJO declares getter and setter methods for the private username instance variable and also for address. The JavaBean specification defines the guidelines for naming these methods. The guidelines allow generic tools like Hibernate to easily discover and manipulate the property value. A getter method name begins with get, followed by the name of the property (the first letter in uppercase); a setter method name begins with set. Getter methods for Boolean properties may begin with is instead of get. Hibernate doesn’t require that accessor methods be declared public; it can easily use private accessors for property management. Some getter and setter methods do something more sophisticated than simple instance variables access (validation, for example). Trivial accessor methods are common, however.
  4. This POJO also defines a business method that calculates the cost of shipping an item to a particular user (we left out the implementation of this method).

public class User
implements Serializable {
private String username;
private Address address;
public User() {}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public MonetaryAmount calcShippingCosts(Address fromLocation) {
...
}
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved