I don't know the main problem you're going to solve but as I guess from the solution, it does not look as the best one to me. But if you want to do it this way, do this:
Make the "type" field transient and add another field to your entity that stores its int value. You can now define an array in your PlaceType class that maps the int values to your final static fields and get the appropriate PlaceType in the getter method of the transient field in the entity.
@Entity
@Table
public class PostalCodeEntity implements Serializable{
@Transient
private PlaceType placeType;
private int type;
public PlaceType getPlaceType() {
return PlaceType.VALUES[type];
}
}
public class PlaceType implements Serializable{
private static final long serialVersionUID = 1L;
private int type;
private String name;
private PlaceType(int type, String name) {
this.type = type;
this.name = name;
}
public int getType() {
return type;
}
public String getName() {
return name;
}
public static final PlaceType[] VALUES = new PlaceType[] {
null, OFFICIAL, RESIDENTIAL, COMMERCIAL
};
public static final PlaceType OFFICIAL = new PlaceType(1, "اداری");
public static final PlaceType RESIDENTIAL = new PlaceType(2, "مسکونی");
public static final PlaceType COMMERCIAL = new PlaceType(3, "تجاری");
}