2 Replies Latest reply on Jan 21, 2011 1:20 AM by Meena Rajani

    Unable to build EntityManagerFactory

    Meena Rajani Newbie

      Hi,

       

      I am using Jboss 6, Eclipse Helios and Postgres 8.4.

      I am getting Unable to build EntityManagerFactory error when deploying a book store application.

       

       

        My persistence.xml is

      <?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="BookAuthorApp3-ejbPU" transaction-type="JTA">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
               <jta-data-source>java:/PostgresDS</jta-data-source>
               <exclude-unlisted-classes>false</exclude-unlisted-classes>
           <properties>
      
       <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
                    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            </properties>
         </persistence-unit>
      </persistence>
      

       

      Here is my PostgresDS.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
      <local-tx-datasource>
      <jndi-name>PostgresDS</jndi-name>
      <connection-url>jdbc:postgresql://localhost:5432/examples4</connection-url>
      <driver-class>org.postgresql.Driver</driver-class>
      <user-name>postgres</user-name>
      <password></password>
      <!-- the minimum size of the connection pool -->
      <min-pool-size>1</min-pool-size>
      <!-- The maximum connections in a pool/sub-pool -->
      <max-pool-size>4</max-pool-size>
      
      <metadata>
               <type-mapping>PostgreSQL 8.4</type-mapping>
            </metadata>
      </local-tx-datasource>
      </datasources>
      

      ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=BookAutho5EAR.ear/BookAutho5.jar#BookAuthorApp3-ejbPU state=Create: javax.persistence.PersistenceException: [PersistenceUnit: BookAuthorApp3-ejbPU] Unable to build EntityManagerFactory

          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:911) [:3.6.0.Final]

          at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) [:3.6.0.Final]

          at org.jboss.jpa.builder.DefaultCEMFBuilder.build(DefaultCEMFBuilder.java:47) [:1.0.2-alpha-1]

          at org.jboss.as.jpa.scanner.HackCEMFBuilder.build(HackCEMFBuilder.java:49) [:6.0.0.20101110-CR1]

          at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:275) [:1.0.2-alpha-1]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_22]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_22]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_22]

          at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_22]

          at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:60) [jboss-reflect.jar:2.2.0.Alpha9]

          at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:168) [jboss-reflect.jar:2.2.0.Alpha9]

          at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66) [jboss-reflect.jar:2.2.0.Alpha9]

          at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:257) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:125) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:72) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:202) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:894) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:641) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:182) [:2.2.0.Alpha8]

          at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:58) [:2.2.0.Alpha8]

          at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62) [:2.2.0.Alpha8]

          at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1832) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1550) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1571) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1603) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1491) [:2.2.0.Alpha8]

          at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:1983) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1076) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679) [:2.2.0.Alpha8]

          at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.process(MainDeployerPlugin.java:106) [:6.0.0.20101110-CR1]

          at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.process(ProfileControllerContext.java:130) [:0.1.0.Alpha1]

          at org.jboss.profileservice.dependency.ProfileDeployAction.deploy(ProfileDeployAction.java:148) [:0.1.0.Alpha1]

          at org.jboss.profileservice.dependency.ProfileDeployAction.installActionInternal(ProfileDeployAction.java:94) [:0.1.0.Alpha1]

          at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42) [jboss-kernel.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.Alpha10]

          at org.jboss.profileservice.dependency.ProfileServiceController.activate(ProfileServiceController.java:188) [:0.1.0.Alpha1]

          at org.jboss.profileservice.AbstractProfileService.activateProfile(AbstractProfileService.java:170) [:0.1.0.Alpha1]

          at org.jboss.profileservice.bootstrap.AbstractProfileServiceBootstrap.activate(AbstractProfileServiceBootstrap.java:117) [:0.1.0.Alpha1]

          at org.jboss.profileservice.resolver.BasicResolverFactory$ProfileResolverFacade.deploy(BasicResolverFactory.java:89) [:0.1.0.Alpha1]

          at org.jboss.profileservice.bootstrap.AbstractProfileServiceBootstrap.start(AbstractProfileServiceBootstrap.java:97) [:0.1.0.Alpha1]

          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:130) [:6.0.0.20101110-CR1]

          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.0.0.20101110-CR1]

          at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

          at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

          at java.lang.Thread.run(Thread.java:662) [:1.6.0_22]

      Caused by: org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile [java.util.Collection(bookentity.ejb.Author.books) : bookentity.ejb.Book]

          at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.mutateRowValueConstructorSyntaxesIfNecessary(BinaryLogicOperatorNode.java:86) [:3.6.0.Final]

          at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.initialize(BinaryLogicOperatorNode.java:75) [:3.6.0.Final]

          at org.hibernate.hql.ast.HqlSqlWalker.prepareLogicOperator(HqlSqlWalker.java:1194) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4414) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1975) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301) [:3.6.0.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244) [:3.6.0.Final]

          at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) [:3.6.0.Final]

          at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) [:3.6.0.Final]

          at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [:3.6.0.Final]

          at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) [:3.6.0.Final]

          at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [:3.6.0.Final]

          at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124) [:3.6.0.Final]

          at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:547) [:3.6.0.Final]

          at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:411) [:3.6.0.Final]

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842) [:3.6.0.Final]

          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902) [:3.6.0.Final]

          ... 77 more

       

      23:47:14,546 INFO  [service] Removing bootstrap log handlers

      23:47:14,593 ERROR [org.jboss.profileservice.bootstrap] Failed to load profile:: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

       

      DEPLOYMENTS MISSING DEPENDENCIES:

        Deployment "jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=AuthorSessionBean,service=EJB3" is missing the following dependencies:

          Dependency "<UNKNOWN jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=AuthorSessionBean,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'persistence.unit:unitName=BookAutho5EAR.ear/BookAutho5.jar#BookAuthorApp3-ejbPU' **")

        Deployment "jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=AuthorSessionBean,service=EJB3_endpoint" is missing the following dependencies:

          Dependency "jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=AuthorSessionBean,service=EJB3" (should be in state "Installed", but is actually in state "PreInstall")

        Deployment "jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=BookSessionBean,service=EJB3" is missing the following dependencies:

          Dependency "<UNKNOWN jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=BookSessionBean,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'persistence.unit:unitName=BookAutho5EAR.ear/BookAutho5.jar#BookAuthorApp3-ejbPU' **")

        Deployment "jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=BookSessionBean,service=EJB3_endpoint" is missing the following dependencies:

          Dependency "jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=BookSessionBean,service=EJB3" (should be in state "Installed", but is actually in state "PreInstall")

       

      DEPLOYMENTS IN ERROR:

        Deployment "persistence.unit:unitName=BookAutho5EAR.ear/BookAutho5.jar#BookAuthorApp3-ejbPU" is in error due to the following reason(s): org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile [java.util.Collection(bookentity.ejb.Author.books) : bookentity.ejb.Book]

        Deployment "<UNKNOWN jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=BookSessionBean,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'persistence.unit:unitName=BookAutho5EAR.ear/BookAutho5.jar#BookAuthorApp3-ejbPU' **

        Deployment "<UNKNOWN jboss.j2ee:ear=BookAutho5EAR.ear,jar=BookAutho5.jar,name=AuthorSessionBean,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'persistence.unit:unitName=BookAutho5EAR.ear/BookAutho5.jar#BookAuthorApp3-ejbPU' **

       

          at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1228) [:2.2.0.Alpha8]

          at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:905) [:2.2.0.Alpha8]

          at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:87) [:6.0.0.20101110-CR1]

          at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAllComplete(ProfileDeployerPluginRegistry.java:118) [:0.1.0.Alpha1]

          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:133) [:6.0.0.20101110-CR1]

          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.0.0.20101110-CR1]

          at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

          at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

          at java.lang.Thread.run(Thread.java:662) [:1.6.0_22]

       

      23:47:14,625 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080

      23:47:14,625 INFO  [org.apache.coyote.ajp.AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009

      23:47:14,625 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.0.0.20101110-CR1 "Neo"] Started in 17s:579ms

       

       

      My Book entity bean is

       

       

      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      
      package bookentity.ejb;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.NamedQueries;
      import javax.persistence.NamedQuery;
      import javax.persistence.Table;
      import javax.persistence.ManyToMany;
      import javax.persistence.JoinTable;
      //import javax.persistence.JoinColumns;
      import javax.persistence.JoinColumn;
      import java.util.Collection;
      import java.util.List;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      //import javax.persistence.inv
      import javax.persistence.OneToMany;
      
      /**
       *
       * @author Administrator
       * Book is in many-to-many relationshi with Author and one-to-many with Review
       */
      @Entity
      @Table(name = "BOOK")
      @NamedQueries({@NamedQuery(name="findBookByAuthorName",query="SELECT b FROM Book b, Author a  WHERE  a.authorName=:authorName AND  a.books=b"),
      @NamedQuery(name="findBookByTitle",query="SELECT b FROM Book b WHERE b.title=:bTitle")})
      //,query="SELECT b.title FROM Book b, Author a WHERE  a.authorName=:authorName OR b.ISBN='8'")
      //query="SELECT b.title FROM Book b, Author a WHERE  a.authorName=:authorName OR b.ISBN='8'")
      //,query="SELECT b.title FROM Book b, Author a WHERE  a.authorName=:authorName OR b.ISBN='8'")
      //This is normal sql query which did not work with ORM infact in code ORM does not refer to Relationship Type Table Book_Author. query="SELECT b.title FROM BOOK b, BOOK_AUTHOR ba, Author a where a.authorName,=:authorName AND a.author_id=ba.AUTHOR_ID AND ba.BOOK_ID=b.ISBN")
      //query="SELECT b.title FROM Book b where b.ISBN=:ISBN")
      public class Book implements Serializable {
          private static final long serialVersionUID = 1L;
          @Id
          private int ISBN;
          private String title;
          private String description;
          private Author author;
         @ManyToMany
          @JoinTable(name="BOOK_AUTHOR", joinColumns=@JoinColumn(name="BOOK_ID"),
         inverseJoinColumns=@JoinColumn(name="AUTHOR_ID"))
          private Collection<Author> authors;
      
         // @OneToMany(fetch=FetchType.EAGER, mappedBy="bookEntity")
         /**    @OneToMany(fetch=FetchType.LAZY, mappedBy="bookEntity")
      public Collection<Review> reviews; 
      
             public Book() {
              authors = new ArrayList<Author>();
              reviews = new ArrayList<Review>();
          } **/
      
          public int getISBN() {
              return ISBN;
          }
      
          public void setISBN(int ISBN) {
              this.ISBN = ISBN;
          }
          public String getTitle(){
              return title;
          }
      
           public void  setTitle(String title){
              this.title =  title;
          }
      
            public String getDescription(){
              return description;
          }
      
           public void  setDescription(String description){
              this.description =  description;
          }
       /**    public void addReview(Review review){
               if(!getReviews().contains(review)){
                   getReviews().add(review);
      
               if(review.getBookEntity()!=null){
                   review.getBookEntity().getReviews().remove(this);
               }
                   review.setBookEntity(this);
               } 
           } **/
           public void addAuthor(Author author){
               if  (!getAuthors().contains(author)){
                       getAuthors().add(author);
                 }
               if(!author.getBooks().contains(this)){
                   author.getBooks().add(this);
               }
           }
      
         /**  public Collection<Review> getReviews(){
               return reviews;
           } **/
      
           public Collection<Author> getAuthors(){
      
               return authors;
           }
      
           void setAuhorId(int authorID) {
      
           } 
      
      
      }
      

       

       

      BooSessionBean is

       

      /**
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      
      package bookentity.ejb;
      import  bookentity.ejb.Book;
      //import ejb.Book;
      //import java.awt.print.Book;
      import java.io.Serializable;
      import java.util.Collection;
      //import java.util.Collection;
      //import java.util.Collection;
      import java.util.Iterator;
      import java.util.List;
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceContext;
      import javax.persistence.Query;
      //import bookentity.ejb.Author;
      import java.util.Random;
      import javax.persistence.PersistenceContextType;
      
      import org.jboss.ejb3.annotation.RemoteBinding;
      
      /**
       *
       * @author Administrator
       */
      @Stateless
      @Remote(BookInterface.class)
      public class BookSessionBean implements BookInterface { 
      @PersistenceContext (unitName = "BookAuthorApp3-ejbPU") 
      //protected EntityManager em;
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("BookAuthorApp3-ejbPU");
      // Ejb3Configuration cfg = new Ejb3Configuration();
      
      //EntityManagerFactory emf = 
      
        protected EntityManager em = emf.createEntityManager();
      
          public void addBook(int isbn){
              // Book bookIns = em.find(Book.class, isbn);
      
               Book bookIns = new Book();
               bookIns.setISBN(isbn);
               bookIns.setTitle("Database" + isbn);
      
               //public void addAuthor(String authName) {
                      //find(Book.class, int bookId);
             // ReviewEntity rev = new ReviewEntity();
             // rev.setBookEntity(book);
             // rev.setBookReview(review);
             Author authorIns = new Author();
              authorIns.addBook(bookIns);
              authorIns.setAuthor_id(isbn);
              authorIns.setAuthorName("Kifer"+ isbn);
              em.persist(authorIns);
              em.persist(bookIns);
      
         // }
      
          }
       /** public void addBook(int isbn, String bName){
              // Book bookIns = em.find(Book.class, isbn);
      
               Book bookIns = new Book();
               bookIns.setISBN(isbn);
               bookIns.setTitle(bName + isbn);
      
      
             Author authorIns = new Author();
              authorIns.addBook(bookIns);
              authorIns.setAuthor_id(isbn);
              authorIns.setAuthorName(aName);
              em.persist(authorIns);
              em.persist(bookIns);
      
         } **/
      
      
          public void addBook(int isbn, String bName, String aName){
              // Book bookIns = em.find(Book.class, isbn);
               System.out.println("this is from addbook");
               Book bookIns = new Book();
               bookIns.setISBN(isbn);
               bookIns.setTitle(bName + isbn);
               System.out.println("this is from addbook");
                em.persist(bookIns);
               //Query q1 = em.createQuery(aName).
               Query q = em.createQuery("SELECT a.author_id FROM Author a WHERE a.authorName='"+aName+"1' OR a.authorName='"+aName+"2' OR a.authorName='"+aName+"3'");
               //"+aName+"1' OR a.authorName='"+aName+"2' OR a.authorName='"+aName+"3'OR a.authorName='
                       //'Herman Hesse'OR a.authorName='Friedrich Nietzsche' OR a.authorName='Abert Camus' OR a.authorName='Nelson Mandela'OR a.authorName= 'Dostoevskey' OR a.authorName= 'Rabindranath Tagore'OR a.authorName= 'Indra Nahru Gandhi' OR a.authorName='Vikram Seth' OR a.authorName='Shah Abdul Latif Bhittaee' OR a.authorName='Galileo'");    
              //  System.out.println("this is from addbook********"+ q.getSingleResult());
      
      
              if(q.getResultList().isEmpty()){
                  Author authorIns1 = new Author();
                  authorIns1.addBook(bookIns);
                  int aid = isbn*3;
                  authorIns1.setAuthor_id(aid);
                  authorIns1.setAuthorName(aName+"3");
                  em.merge(authorIns1);
                  Author authorIns2 = new Author();
                  authorIns2.addBook(bookIns);
                  aid= aid-1;
                  authorIns2.setAuthor_id(aid);
                  authorIns2.setAuthorName(aName+"2");
                  em.merge(authorIns2);
                   Author authorIns3 = new Author();
                  authorIns3.addBook(bookIns);
                  aid = aid-1;
                  authorIns3.setAuthor_id(aid);
                  authorIns3.setAuthorName(aName+"1,");
                  em.persist(authorIns3);
      
              }
              else 
              {    List<Author> aList= q.getResultList();
                   for(Iterator iter= aList.iterator(); iter.hasNext(); ){
                       int AuthorId= (Integer) iter.next();        
                            //int aId= (Integer) q.getSingleResult();
                            Author aa = em.find(Author.class, AuthorId);
                            aa.addBook(bookIns);
                            em.persist(aa);
                  //aa.setAuthor_id(aId);
                  //authorIns.setAuthorName(aName);
                   }
      
              } 
      
           }
          public void addBookWithExistingAuthor(int bid, String bname){
              System.out.println("this is from addWithExisting Author");
              Book b = new Book();
              b.setISBN(bid);
              b.setTitle(bname+bid);
               System.out.println("this is from addWithExisting Author");
              em.persist(b);
              System.out.println("this is from addWithExisting Author");
              Random rm  = new Random();
              for(int i =1; i<=3; i++){
                  //System.out.println(bname[rm.nextInt(9)]);
                  //int j = rm.nextInt(60);
                  int j = rm.nextInt(20) + 1;
                  System.out.println("Random j = " + j);
                  Author a = em.find(Author.class, j);
      
                  System.out.println("book id"+ b.getISBN());
                     System.out.println(a.authAddress);
      
                  a.addBook(b);
                  em.persist(a);
              }
      
          }
      
       public List<Book>  findBookByTitle(String title){
           List li = em.createNamedQuery("findBookByTitle").setParameter("bTitle",title).getResultList(); if(li.size()>0){
                 for(int i=0; i<li.size();i++){
                   ((Book)li.get(i)).getAuthors().size();
                 //  ((Book)li.get(i)).getReviews().size();
                 }
              }       
              return li;
      
        }
           public Book  findBook(int isbn) {
              Book bookIns = em.find(Book.class, isbn);
              return bookIns;
          }
           public List<Book>  findBookByAuthorName(String authorName) {
                System.out.println("test messege for loop");
                List li = em.createNamedQuery("findBookByAuthorName").setParameter("authorName", authorName).getResultList();
               System.out.println("test messege for loop after index");
              StringBuffer buffer = new StringBuffer();
           //   for(Iterator iter = bookresult.iterator(); iter.hasNext();){
           //       buffer.append(buffer.toString());
          //       System.out.println( iter.next());
            //  }
               //List lii = bookresult;
      
             // System.out.println("test messege for loop");   
              if(li.size()>0){
                 for(int i=0; i<li.size();i++){
                   ((Book)li.get(i)).getAuthors().size();
                 //  ((Book)li.get(i)).getReviews().size();
                 }
              }       
              return li;
                         //bookresult;
              //System.out.println(bookins.toString());
              // System.out.println("this is from booksessionbean findbookbyauthor");
      
          } 
      
      
            public List<Book> getAllBooks(){
              Query q = em.createQuery("SELECT b FROM Book b");
      
               List li =  q.getResultList();
             if(li.size()>0){
                 for(int i=0; i<li.size();i++){
                   ((Book)li.get(i)).getAuthors().size();
                 //  ((Book)li.get(i)).getReviews().size();
                 }
      
      
      
             } 
              return li;  
      
          }  
      
      
      
      
      
      }
      

       

        • 1. Unable to build EntityManagerFactory
          jaikiran pai Master

          Here's the root cause:

           

           

          Caused by: org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile [java.util.Collection(bookentity.ejb.Author.books) : bookentity.ejb.Book]

              at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.mutateRowValueConstructorSyntaxesIfNecessary(BinaryLogicOperatorNode.java:86) [:3.6.0.Final]

          • 2. Unable to build EntityManagerFactory
            Meena Rajani Newbie

            Hi Thanks for the answer, 

             

             

            How ever the problem was in NamedQuery, i was using toplink before when I swiched to Hibernate I used same code. Some how

            @NamedQuery(name="findBookByAuthorName",query="SELECT b FROM Book b, Author a  WHERE  a.authorName=:authorName AND a.books= b")

            which was working perfectly was not working with Hibernate. So far I have substituted   (a.books= b) " =" with 'in' . It is depying the entity bean properly and creating database with data too. But after this substitution I am getting messgeNull from the result of query which is making a join.

             

            Other error which I had was that accidently I had put an annotation EJB in my client also. Removing that annotation resolved the error "unable to build enetity manage"

             

             

            Cheers

             

            Meena