Read the article on Dao 's General Approach .
I do not understand your problem, but if you want to get the identifier of an object, just get it. Its available method after saving is completed, i.e.
em.persist(entity); et.commit(); int id = entity.getId()
I usually make an AbstractEntity class with the id field and its accessories and inherit all my other objects from this class.
The only problem with this approach is that if you need to make any of your entities Serializable, you will have to make AbstractEntity serializable, i.e. all other objects will become serializable. Otherwise, the id field will not be serialized in the entity to be serialized.
Roman Jul 25 '10 at 11:13 2010-07-25 11:13
source share