title: Java, convert(cast) Serializable objects to other objects
body: <p>I'm using <code>Session.save()</code> method (in Hibernate) to persist my entity objects which returns an object of type <code>java.io.Serializable</code>.</p>
  
  <p>The returned value is the generated primary key for the entity.</p>
  
  <p>The generated primary key is of type <code>long</code> (or bigint).</p>
  
  <p>The question is that: How can I convert or cast the returned value to <code>long</code>?</p>
  
  <pre><code>Serializable result = session.save(myEntityObject);
  
  //This line of code fails. 
  long r = (long)result;
  </code></pre>