I want to make my entity a singleton. That singleton should be accessible from other entities.
So I decide to set its id manyally, like:
@Entity
@Table(name = "tableName")
public class SingletonEntity {
@Id
private int id = this.getClass().getSimpleName(); //IS IT POSSIBLE? HOW?
//.......
}
Question:
How to achieve that? Please. give me an example.
EDIT:
It is worth to say that my SingletonEntity 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 SingletonEntity.class.getSimpleName()
For @Balaji Reddy:
I've tried:
@Entity
@Table(name = "Client")
public class Client implements Serializable {
@Id
@Column(name = "id")
private static final String id = Client.class.getSimpleName();
.................
}
And get:
No identifier specified for entity: db.Client
in string
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
State Pattern. Each of my states is a singleton. I can make them a spring beans, but there is a little problem. Each of those states has it own state (final in my case). So if I make them a spring beans I need to recompiling my app each time I want to change their state. I see the solution in making them a singleton entities. See also stackoverflow.com/questions/20091168/…