primary key « Eclipse « JPA Q&A

1. Removing an entity, but using the same primary key to add a similar entity after the removal

Im trying to remove an entity which has a unique PK like : 80253 I remove this entity by doing the follow lines of code:

myEntityType1 = getEntityManager().find(MyEntityType1.class, 80253);
These bits of code ...

2. How to handle "null primary key encountered" exception in eclipselink?

... Null primary key encountered in unit of work clone ...
exception in eclipselink(2.0.2 with 2.0 jpa) literally meaning that id in my entity is <=0 (for primitive types). Though debug here ...

3. How to get the primary key of any JPA entity?

For every @Entity I need to perform the following:

public <Entity> boolean insert(final Entity entity){
    if (em.find(entity.getClass(), entity.getId()) == null) {

4. Extract the primary key from a entity object in JPA 2.0?

Let's say we have an entity object. Is there a way to extract a primary key from it? I want to do something like this:

public static Object extractPrimaryKey(EntityManager em, Object obj) {

5. java hibernate eclipse xml - use an entity without a primary key

I have one question that if we are creating any table in database i.e. not having any primary key(all columns values are nullable). can't we do mapping without ID field in Hibernate ...