title: Hibernate: entity class name as identifier
body: <p><strong>I want to make my entity a singleton. That singleton should be accessible from other entities.</strong> </p>
  
  <p>So I decide to set its id manyally, like:</p>
  
  <pre><code>@Entity
  @Table(name = "tableName")
  public class SingletonEntity {
  
    @Id
    private int id = this.getClass().getSimpleName(); //IS IT POSSIBLE? HOW?
  
    //.......
  }
  </code></pre>
  
  <p><em><strong>Question:</em></strong></p>
  
  <p><em>How to achieve that?</em> Please. give me an example.</p>
  
  <p><em><strong>EDIT:</em></strong></p>
  
  <p>It is worth to say that my <code>SingletonEntity</code> has only final string state. So I can say that its stateless. Actually, I don't want a singleton, I only want to set final id to that entity, and I want that id should be equals to <code>SingletonEntity.class.getSimpleName()</code></p>
  
  <p><em><strong>For @Balaji Reddy:</em></strong></p>
  
  <p>I've tried:</p>
  
  <pre><code>@Entity
  @Table(name = "Client")
  public class Client implements Serializable {
  
      @Id
      @Column(name = "id")
      private static final String id = Client.class.getSimpleName();
  
      .................
  }
  </code></pre>
  
  <p>And get:</p>
  
  <blockquote>
    <p>No identifier specified for entity: db.Client</p>
  </blockquote>
  
  <p>in string </p>
  
  <pre><code>ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
  </code></pre>