facebook

[Closed] EJB3 out of container persistence w/ mysql/Eclipse5

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #274540 Reply

    Andy Ghosh
    Member

    Hi,
    I am testing a very simple application involving EJB3 annotations and persistenace out of container.

    I am listing the entity class, client class and the persistence file and the exception I am getting. The persistence.xml is located in the project META-INF directory.

    Any help is appreciated!
    Thanks
    Andy

    Entity Class

    
    package com.andy.ejb3;
    
    import javax.persistence.Entity;
    import javax.persistence.EntityManager;
    import javax.persistence.Id;
    
    @Entity
    public class Book {
    
        
        @Id
        private int book_id;
    
        public Book() {
        }
    
        protected EntityManager em;
        private String book_name;
        private int publisher_id;
    
        
        public Book(EntityManager em){
            this.em=em;
        }
        
        
    }
    

    And I created a persistence.xml like this:

    
    <?xml version="1.0" encoding="UTF-8"?> 
    <persistence 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" version="1.0"> 
    <persistence-unit name="Book" transaction-type="RESOURCE_LOCAL"> 
    <provider>oracle.toplink.essentials.PersistenceProvider</provider> 
    <class>com.andy.ejb3.Book</class> 
    <properties> 
    <property name = "toplink.jdbc.driver" value = "com.mysql.jdbc.Driver"/> 
    <property name = "toplink.jdbc.url" value = "jdbc:mysql://127.0.0.1:3306/test"/> 
    <property name = "toplink.jdbc.user" value = "root"/> 
    <property name = "toplink.jdbc.password" value = "root"/> 
    </properties> 
    </persistence-unit> 
    </persistence> 
    

    Finally I have client code like this:

    
    EntityManagerFactory emf =
                   Persistence.createEntityManagerFactory("Book");
                   EntityManager em = emf.createEntityManager();
                   Book svc=new Book(em);
                   em.getTransaction().begin();
                   
                   Book b=svc.CreateBook(999, "Exorcist", 876);
                   
                   em.getTransaction().commit();
    

    I am getting an exception:

    
    Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Book
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
        at com.andy.ejb3.MyBeanClient.main(MyBeanClient.java:27)
    
    #274548 Reply

    Andy Ghosh
    Member

    Never mind, it was a classpath issue with the entity manager provider. Thanks

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: [Closed] EJB3 out of container persistence w/ mysql/Eclipse5

You must be logged in to post in the forum log in