Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Adella Garcia   on Apr 17 In Java Category.

  
Question Answered By: Sumitra 2004   on Apr 17

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, "تجاری");

}

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Hibernate Or get search suggestion and latest updates.


Tagged: