title: Hibernate: Save Double to Database as Int
body: <p>does anyone know how I can create a Java POJO which has stores a double in memory but an integer on disk?  </p>
  
  <p>I would like to store these objects to disk as integers, because I have 100 million of them, and that would save space.  However, sometimes my Java code manipulates the values in memory (without saving them) and turns them into real numbers</p>
  
  <p>I have tried something like:</p>
  
  <pre><code>@Entity
  @Table(name = "POJO")
  public class POJO {
  @Id
  @GeneratedValue
  @Column(name = "id")
  int id;
  
  @Column(name = "value")
  int valueInteger; // this is weird:  in the database, we want to use integers, to save space.  but in memory, sometimes we use real values
  double value;
  
  public int getValueInteger() {
      return valueInteger;
  }
  
  public void setValueInteger(int valueInteger) {
      this.valueInteger = valueInteger;
      this.value = valueInteger;
  }
  
  public double getValue() {
      return value;
  }
  
  public void setValue(double value) {
      this.value = value;
      // might want to call setValueInteger() here if consistency is required.  Right now, I think it's not, so I'll leave it out.
  }
  }
  </code></pre>
  
  <p>This is not a terrible solution, except the memory footprint is larger than needed.  Is there some way to have the POJO have only a double (and the ID of course), and instruct hibernate to force a double to integer conversion when it stores to the database (for instance, by rounding that double)?</p>
  
  <p>Thanks for the help!</p>