jsf - java.lang.IllegalArgumentException: Object: se.nackademin.BeachBoysSweden.entities.Book@79da4980 is not a known entity type -


im working on school assignment keep getting java.lang.illegalargumentexception when trying save entity mysql database. project uses jpa, ejb, jsf, glassfish , connection pool.keep in minde im new java web development.

entity:

import javax.inject.named; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.id;  import javax.persistence.generatedvalue; import javax.persistence.generationtype;  import javax.persistence.table;   @named @conversationscoped @entity @table(name = "books") public class book implements serializable{          private static final long serialversionuid = 1l;          @id         @column(name = "book_id")         @generatedvalue(strategy = generationtype.auto)           private long bookid;          @column(name = "title")         private string title;          @column(name = "author")         private string author;          @column(name = "price")         private int price;          public book(){          }          public long getbookid() {                 return bookid;         }          public void setbookid(long bookid) {                 this.bookid = bookid;         }          public string gettitle() {                 return title;         }          public void settitle(string title) {                 this.title = title;         }          public string getauthor() {                 return author;         }          public void setauthor(string author) {                 this.author = author;         }          public int getprice() {                 return price;         }          public void setprice(int price) {                 this.price = price;         }  }//end class 

dao object:

import java.util.list;   import javax.ejb.localbean; import javax.ejb.stateless; import javax.persistence.entitymanager; import javax.persistence.persistencecontext; import javax.persistence.query;    @stateless @localbean public class bookdaobean implements bookdao {       @persistencecontext     private entitymanager entitymanager;        @suppresswarnings("unchecked")     public list<book> getbooks() {          list<book> matchingbookslist;          query query = entitymanager.createquery("select s book s");          matchingbookslist = query.getresultlist();           return matchingbookslist;     }       @override     public void savebook(book book) {          if(book.getauthor() != null){               entitymanager.persist(book);            }else{              system.out.println("book object id " + book.getbookid());          }      }  }//end class 

controller:

import javax.ejb.ejb; import javax.enterprise.context.conversation; import javax.enterprise.context.requestscoped; import javax.inject.inject; import javax.inject.named;  import se.nackademin.beachboyssweden.dao.bookdaobean; import se.nackademin.beachboyssweden.entities.book;    @named @requestscoped  public class bookcontroller {      @ejb     private bookdaobean bookdao;     @inject     private book book;     @inject     private conversation conversation;       public string enterform(){         conversation.begin();         system.out.print("enter form");         return "form";     }      public string gotoconfirmation(){         return "confirmation";      }      public string savebook(){            bookdao.savebook(book);         conversation.end();         return "list";     }  } 

persistence.xml:

<?xml version="1.0" encoding="utf-8"?> <persistence version="1.0"     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://java.sun.com/xml/ns/persistence        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">     <persistence-unit name="book4persistenceunit"         transaction-type="jta">         <jta-data-source>jdbc/__bookpool</jta-data-source>         <exclude-unlisted-classes>false</exclude-unlisted-classes>     </persistence-unit> </persistence>  

root case:

warning: standardwrappervalve[faces servlet]: pwc1406: servlet.service() servlet faces servlet threw exception java.lang.illegalargumentexception: object: se.nackademin.beachboyssweden.entities.book@73b9c795 not known entity type.     @ org.eclipse.persistence.internal.sessions.unitofworkimpl.registernewobjectforpersist(unitofworkimpl.java:4169)     @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.persist(entitymanagerimpl.java:440)     @ com.sun.enterprise.container.common.impl.entitymanagerwrapper.persist(entitymanagerwrapper.java:269) 

since using annotated classes. have tell hibernate files can scanned annotations.

<persistence-unit name="book4persistenceunit"         transaction-type="jta">     <!-- explicitly define entities in class tags -->     <class>book</class>      <properties>           <!-- scan annotated classes , hibernate mapping xml files -->           <property name="hibernate.archive.autodetection" value="class, hbm"/>     </properties> </persistence-unit> 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -