lundi 18 mai 2015

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

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

Java Code:
Java Code:

  1.  
  2. public String save() {
  3. PersonDAO dao = new PersonDAO();
  4.  
  5. dao.create(user);
  6. return "/registry.xhtml";
  7. }


Die DAO sieht hierbei wie folgt aus

Java Code:

  1.  
  2. public class PersonDAO extends GenericDAO<Person> {}


Java Code:

  1.  
  2. public class GenericDAO<T> implements AbstractBasicDAO<T> {
  3. /**
  4.   * the entity manager
  5.   *
  6.   * @var EntityManager
  7.   */
  8. protected EntityManager em;
  9.  
  10. /**
  11.   * this is the class type to handle
  12.   *
  13.   * @var Class<T>
  14.   */
  15. private Class<T> type;
  16.  
  17. /**
  18.   * default constructor
  19.   */
  20. public GenericDAO() {
  21. Type t = getClass().getGenericSuperclass();
  22. ParameterizedType pt = (ParameterizedType) t;
  23.  
  24. type = (Class) pt.getActualTypeArguments()[0];
  25. this.em = EntityManagerUtil.getEntityManager();
  26. }
  27.  
  28. /**
  29.   * Make an instance managed and persistent.
  30.   *
  31.   * @param t the entity to store
  32.   * @return the stored entity
  33.   */
  34. @Override
  35. public T create(final T t) {
  36. this.em.persist(t);
  37. return t;
  38. }
  39.  
  40. /**
  41.   * Find by a spezified primary key.
  42.   *
  43.   * @param id the id to find
  44.   * @return the found entity
  45.   */
  46. @Override
  47. public T find(final Object id) {
  48. return (T) this.em.find(type, id);
  49. }
  50.  
  51. /**
  52.   * Find all entites by an given query
  53.   *
  54.   * @param sql the sql query
  55.   * @return the found entity
  56.   */
  57. @Override
  58. public List find(String sql) {
  59. return em.createQuery(sql).getResultList();
  60. }
  61.  
  62. /**
  63.   * Merge the state of the given entity into the current persistence context.
  64.   *
  65.   * @param t the entity to store
  66.   * @return the stored entity
  67.   */
  68. @Override
  69. public T update(final T t) {
  70. return this.em.merge(t);
  71. }
  72.  
  73. /**
  74.   * delete an object by his pramary key
  75.   *
  76.   * @param id the priamary key to delete
  77.   */
  78. @Override
  79. public void delete(final Object id) {
  80. this.em.remove(this.em.getReference(type, id));
  81. }
  82.  
  83. }



Der EntityManager sieht wie folgt aus
Java Code:

  1.  
  2. public class EntityManagerUtil {
  3. final static org.apache.log4j.Logger logger = Logger.getLogger(EntityManagerUtil.class);
  4.  
  5. /**
  6.   * the entity manager
  7.   *
  8.   * @var EntityManager
  9.   */
  10. private static EntityManager entityManager;
  11.  
  12. /**
  13.   * default constructor
  14.   *
  15.   * @throw ExceptionInInitializerError
  16.   */
  17. static {
  18. try {
  19. EntityManagerFactory factory = Persistence.createEntityManagerFactory("JAPPU");
  20. entityManager = factory.createEntityManager();
  21. } catch( Throwable ex ) {
  22. logger.error("Error on EntityManager inializing", ex);
  23. throw new IllegalStateException(ex);
  24. }
  25. }
  26.  
  27. /**
  28.   * get the EntityManager
  29.   *
  30.   * @return EntityManager
  31.   */
  32. public static EntityManager getEntityManager() {
  33. return entityManager;
  34. }
  35. }



Die Entity sieht wie folgt aus
Java Code:

  1.  
  2. package com.abado.jap.entities.user;
  3.  
  4. import java.io.Serializable;
  5. import java.util.Collection;
  6. import java.util.Date;
  7. import javax.persistence.*;
  8. import javax.validation.constraints.NotNull;
  9. import javax.validation.constraints.Size;
  10. import javax.xml.bind.annotation.XmlTransient;
  11.  
  12. @Table(name="person")
  13. public class Person implements Serializable {
  14. @Id
  15. @GeneratedValue(strategy = GenerationType.AUTO)
  16. @Basic(optional = false)
  17. @Column(name = "id")
  18. private Long id;
  19.  
  20. @OneToMany(mappedBy = "createdBy")
  21. private Collection<Person> creators;
  22. @JoinColumn(name = "created_by", referencedColumnName = "id")
  23. @ManyToOne
  24. private Person createdBy;
  25.  
  26. @Column(name = "created_at")
  27. @Temporal(TemporalType.TIMESTAMP)
  28. private Date created_at;
  29.  
  30. @OneToMany(mappedBy = "modifiedBy")
  31. private Collection<Person> modifiers;
  32. @JoinColumn(name = "modified_by", referencedColumnName = "id")
  33. @ManyToOne
  34. private Person modifiedBy;
  35.  
  36. @Column(name = "modified_at")
  37. @Temporal(TemporalType.TIMESTAMP)
  38. private Date modified_at;
  39.  
  40. @Basic(optional = false)
  41. @NotNull
  42. @Column(name = "block")
  43. private boolean block;
  44.  
  45. @Size(max = 255)
  46. @Column(name = "active_code")
  47. private String activeCode;
  48.  
  49. @Column(name = "gender")
  50. private EGender gender;
  51.  
  52. @Column(name = "firstname")
  53. private String firstname;
  54.  
  55. @Column(name = "lastname")
  56. private String lastname;
  57.  
  58. @Column(name = "birthdate")
  59. @Temporal(TemporalType.TIMESTAMP)
  60. private Date birthdate;
  61.  
  62. @Column(name = "email")
  63. private String email;
  64.  
  65. @Column(name = "password")
  66. private String password;
  67.  
  68. /**
  69.   * default constructor
  70.   */
  71. public Person() {
  72. }
  73.  
  74. //--- GETTER / SETTER
  75. public Long getId() {
  76. return id;
  77. }
  78.  
  79. public void setId(Long id) {
  80. this.id = id;
  81. }
  82.  
  83. public Person getCreatedby() {
  84. return createdBy;
  85. }
  86.  
  87. public void setCreatedBy(Person created_by) {
  88. this.createdBy = created_by;
  89. }
  90.  
  91. @XmlTransient
  92. public Collection<Person> getCreators() {
  93. return creators;
  94. }
  95.  
  96. public void setCreators(Collection<Person> creators) {
  97. this.creators = creators;
  98. }
  99.  
  100. public Date getCreatedAt() {
  101. return created_at;
  102. }
  103.  
  104. public void setCreatedAt(Date created_at) {
  105. this.created_at = created_at;
  106. }
  107.  
  108. public Person getModifiedBy() {
  109. return modifiedBy;
  110. }
  111.  
  112. public void setModified_by(Person modified_by) {
  113. this.modifiedBy = modified_by;
  114. }
  115.  
  116. @XmlTransient
  117. public Collection<Person> getModifiers() {
  118. return modifiers;
  119. }
  120.  
  121. public void setModifiers(Collection<Person> modifiers) {
  122. this.modifiers = modifiers;
  123. }
  124.  
  125. public Date getModified_at() {
  126. return modified_at;
  127. }
  128.  
  129. public void setModified_at(Date modified_at) {
  130. this.modified_at = modified_at;
  131. }
  132.  
  133. public boolean getBlock() {
  134. return block;
  135. }
  136.  
  137. public void setBlock(boolean block) {
  138. this.block = block;
  139. }
  140.  
  141. public String getActiveCode() {
  142. return activeCode;
  143. }
  144.  
  145. public void setActiveCode(String activeCode) {
  146. this.activeCode = activeCode;
  147. }
  148.  
  149. public EGender getGender() {
  150. return gender;
  151. }
  152.  
  153. public void setGender(EGender gender) {
  154. this.gender = gender;
  155. }
  156.  
  157. public String getFirstname() {
  158. return firstname;
  159. }
  160.  
  161. public void setFirstname(String firstname) {
  162. this.firstname = firstname;
  163. }
  164.  
  165. public String getLastname() {
  166. return lastname;
  167. }
  168.  
  169. public void setLastname(String lastname) {
  170. this.lastname = lastname;
  171. }
  172.  
  173. public Date getBirthdate() {
  174. return birthdate;
  175. }
  176.  
  177. public void setBirthdate(Date birthdate) {
  178. this.birthdate = birthdate;
  179. }
  180.  
  181. public String getEmail() {
  182. return email;
  183. }
  184.  
  185. public void setEmail(String email) {
  186. this.email = email;
  187. }
  188.  
  189. public String getPassword() {
  190. return password;
  191. }
  192.  
  193. public void setPassword(String password) {
  194. this.password = password;
  195. }
  196.  
  197. /**
  198.   *
  199.   * @return
  200.   */
  201. @Override
  202. public int hashCode() {
  203. int hash = 0;
  204. hash += (id != null ? id.hashCode() : 0);
  205. return hash;
  206. }
  207.  
  208. /**
  209.   *
  210.   * @param object
  211.   * @return
  212.   */
  213. @Override
  214. public boolean equals(Object object) {
  215. // TODO: Warning - this method won't work in the case the id fields are not set
  216. if (!(object instanceof Person)) {
  217. return false;
  218. }
  219.  
  220. Person other = (Person) object;
  221. if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
  222. return false;
  223. }
  224.  
  225. return true;
  226. }
  227.  
  228. /**
  229.   *
  230.   * @return
  231.   */
  232. @Override
  233. public String toString() {
  234. return "com.abado.jap.entities.user.Person[ id=" + id + " ]";
  235. }
  236. }


Die persistence.xml
Code:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.1" xmlns="http://ift.tt/1m1OuvG; xmlns:xsi="http://ift.tt/Atvu06; xsi:schemaLocation="http://ift.tt/1cKbVbQ http://ift.tt/1vizMH7;
      <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
Zitat:

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)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Object: com.abado.jap.entities.user.Person[ id=null ] is not a known entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4228)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496)
at com.abado.jap.utils.database.impl.GenericDAO.create(GenericDAO.java:52)
at com.abado.jap.services.UserService.save(UserService.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more
Weis einer von euch wieso ich den Fehler erhalte?


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

0 commentaires:

Enregistrer un commentaire