# IllegalArgumentException: Person[ id=null ] is not a known entity type.???



## TomTank (18. Mai 2015)

Ich arbeite gerad an einem Project mit JSF, EclipseLink. Wenn ich mein Formular abschicke rufe ich

Java Code:

```
public String save() {
                  PersonDAO dao = new PersonDAO();
     
                  dao.create(user);
                  return "/registry.xhtml";
           }
```
 
Die DAO sieht hierbei wie folgt aus


```
public class PersonDAO extends GenericDAO<Person> {}
```
 

```
public class GenericDAO<T> implements AbstractBasicDAO<T> {
           /**
            * the entity manager
            *
            * @var      EntityManager
            */
           protected EntityManager em;
           
           /**
            * this is the class type to handle
            *
            * @var      Class<T>
            */
           private Class<T> type;
     
           /**
            * default constructor
            */
           public GenericDAO() {
                  Type              t  = getClass().getGenericSuperclass();
                  ParameterizedType pt = (ParameterizedType) t;
                 
                  type = (Class) pt.getActualTypeArguments()[0];              
                  this.em = EntityManagerUtil.getEntityManager();
           }
           
           /**
            * Make an instance managed and persistent.
            *
            * @param    t   the entity to store
            * @return       the stored entity
            */
           @Override
           public T create(final T t) {
                    this.em.persist(t);
                    return t;
           }
           
           /**
            * Find by a spezified primary key.
            *
            * @param    id  the id to find
            * @return       the found entity
            */
            @Override
            public T find(final Object id) {
                   return (T) this.em.find(type, id);
            }
           
           /**
            * Find all entites by an given query
            *
            * @param    sql     the sql query
            * @return   the found entity
            */        
            @Override
            public List find(String sql) {
                   return em.createQuery(sql).getResultList();
            }        
           
           /**
            * Merge the state of the given entity into the current persistence context.
            *
            * @param    t   the entity to store
            * @return       the stored entity
            */      
           @Override
           public T update(final T t) {
                  return this.em.merge(t);    
           }
           
           /**
            * delete an object by his pramary key
            *
            * @param    id   the priamary key to delete
            */              
           @Override
           public void delete(final Object id) {
                  this.em.remove(this.em.getReference(type, id));
           }
     
    }
```


Der EntityManager sieht wie folgt aus

```
public class EntityManagerUtil {
           final static org.apache.log4j.Logger logger = Logger.getLogger(EntityManagerUtil.class);
           
           /**
        * the entity manager
            *
            * @var  EntityManager
        */
           private static EntityManager entityManager;
     
           /**
            * default constructor
            *
            * @throw    ExceptionInInitializerError
            */
           static {
                  try {
                      EntityManagerFactory factory = Persistence.createEntityManagerFactory("JAPPU");
                      entityManager = factory.createEntityManager();
                  } catch( Throwable ex ) {
                        logger.error("Error on EntityManager inializing", ex);
                        throw new IllegalStateException(ex);
                  }              
           }
           
           /**
            * get the EntityManager
            *
            * @return   EntityManager
            */
           public static EntityManager getEntityManager() {
                  return entityManager;
           }
    }
```


Die Entity sieht wie folgt aus

```
package com.abado.jap.entities.user;
     
    import java.io.Serializable;
    import java.util.Collection;
    import java.util.Date;
    import javax.persistence.*;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlTransient;
     
    @Entity
    @Table(name="person")
    public class Person implements Serializable {      
           @Id
           @GeneratedValue(strategy = GenerationType.AUTO)
           @Basic(optional = false)
           @Column(name = "id")
           private Long id;
     
           @OneToMany(mappedBy = "createdBy")
           private Collection<Person> creators;
           @JoinColumn(name = "created_by", referencedColumnName = "id")
           @ManyToOne
           private Person createdBy;
                 
           @Column(name = "created_at")
           @Temporal(TemporalType.TIMESTAMP)
           private Date        created_at;
           
           @OneToMany(mappedBy = "modifiedBy")
           private Collection<Person> modifiers;
           @JoinColumn(name = "modified_by", referencedColumnName = "id")
           @ManyToOne
           private Person modifiedBy;
           
           @Column(name = "modified_at")              
           @Temporal(TemporalType.TIMESTAMP)      
           private Date        modified_at;
     
           @Basic(optional = false)
           @NotNull
           @Column(name = "block")
           private boolean block;
       
           @Size(max = 255)
           @Column(name = "active_code")
           private String activeCode;
           
           @Column(name = "gender")              
           private EGender     gender;
           
           @Column(name = "firstname")                    
           private String      firstname;
           
           @Column(name = "lastname")                            
           private String      lastname;
           
           @Column(name = "birthdate")  
           @Temporal(TemporalType.TIMESTAMP)    
           private Date        birthdate;
           
           @Column(name = "email")                                          
           private String      email;
           
           @Column(name = "password")                                                
           private String      password;
     
           /**
            * default constructor
            */
           public Person() {
           }
     
           //--- GETTER / SETTER
           public Long getId() {
                  return id;
           }
     
           public void setId(Long id) {
                  this.id = id;
           }
     
           public Person getCreatedby() {
                  return createdBy;
           }
     
           public void setCreatedBy(Person created_by) {
                  this.createdBy = created_by;
           }
     
           @XmlTransient
           public Collection<Person> getCreators() {
                  return creators;
           }
     
           public void setCreators(Collection<Person> creators) {
                  this.creators = creators;
           }
     
           public Date getCreatedAt() {
                  return created_at;
           }
     
           public void setCreatedAt(Date created_at) {
                  this.created_at = created_at;
           }
     
           public Person getModifiedBy() {
                  return modifiedBy;
           }
     
           public void setModified_by(Person modified_by) {
                  this.modifiedBy = modified_by;
           }
       
           @XmlTransient
           public Collection<Person> getModifiers() {
                  return modifiers;
           }
     
           public void setModifiers(Collection<Person> modifiers) {
                  this.modifiers = modifiers;
           }
       
           public Date getModified_at() {
                  return modified_at;
           }
     
           public void setModified_at(Date modified_at) {
                  this.modified_at = modified_at;
           }
           
           public boolean getBlock() {
                  return block;
           }
     
           public void setBlock(boolean block) {
                  this.block = block;
           }
     
           public String getActiveCode() {
                  return activeCode;
           }
     
           public void setActiveCode(String activeCode) {
                  this.activeCode = activeCode;
           }
       
           public EGender getGender() {
                  return gender;
           }
     
           public void setGender(EGender gender) {
                  this.gender = gender;
           }
     
           public String getFirstname() {
                  return firstname;
           }
     
           public void setFirstname(String firstname) {
                  this.firstname = firstname;
           }
     
           public String getLastname() {
                  return lastname;
           }
     
           public void setLastname(String lastname) {
                  this.lastname = lastname;
           }
     
           public Date getBirthdate() {
                  return birthdate;
           }
     
           public void setBirthdate(Date birthdate) {
                  this.birthdate = birthdate;
           }
     
           public String getEmail() {
                  return email;
           }
     
           public void setEmail(String email) {
                  this.email = email;
           }
     
           public String getPassword() {
                  return password;
           }
     
           public void setPassword(String password) {
                  this.password = password;
           }      
           
           /**
            *
            * @return
            */
           @Override
           public int hashCode() {
                  int hash = 0;
                  hash += (id != null ? id.hashCode() : 0);
                  return hash;
           }
     
           /**
            *
            * @param object
            * @return
            */
           @Override
           public boolean equals(Object object) {
                  // TODO: Warning - this method won't work in the case the id fields are not set
                  if (!(object instanceof Person)) {
                     return false;
                  }
                 
                  Person other = (Person) object;
                  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                     return false;
                  }
     
                  return true;
           }
     
           /**
            *
            * @return
            */
           @Override
           public String toString() {
                  return "com.abado.jap.entities.user.Person[ id=" + id + " ]";
           }
    }
```

Die persistence.xml

```
<?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
      <persistence-unit name="JAPPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.abado.jap.entities.user.Person</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
          <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jap?zeroDateTimeBehavior=convertToNull"/>
          <property name="javax.persistence.jdbc.user" value="root"/>
          <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
          <property name="javax.persistence.jdbc.password" value=""/>
          <property name="javax.persistence.schema-generation.database.action" value="create"/>
        </properties>
      </persistence-unit>
    </persistence>
```

Wenn ich jetzt allerdings das Formular abschicke über die obige save-Methode
wird mir ausgeaben


> javax.faces.el.EvaluationException: java.lang.IllegalArgumentException: Object: com.abado.jap.entities.user.Person[ id=null ] is not a known entity type.
> at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
> at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
> at javax.faces.component.UICommand.broadcast(UICommand.java:315)
> ...



Weis einer von euch wieso ich den Fehler erhalte?


----------

