facebook

JPA – findAll() exception: looking for an ID class?

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #313490 Reply

    dason
    Member

    I have a very simple table in an oracle database. Named DAVETEMP.
    It has the following columns:
    1. ID defined as a NUMBER and is the primary key
    2. EVENT_DATE defined as a DATE
    3. TEXT defined as VARCHAR2(500)

    When I create a JPA project in MyEclipse 8.6 and attempt to reverse engineer this table, it creates the following classes for me:
    DaveTemp.java
    DaveTempDAO.java
    EntityManagerHelper.java
    IDaveTempDAO.java

    When I attempt to get a list of the values in the table calling:
    daveTempDAO.findAll()

    I get an exception:
    java.lang.ClassNotFoundException: com.test.jpa.DaveTempId

    Any thoughts on where this DaveTempId class needs to come from?

    Thanks for the help,
    Dave

    #313499 Reply

    support-swapna
    Moderator

    dason,

    I tried working on the findAll() and it is working fine for me.
    Can you tell me which database you are using?
    Can you also send me the file in which you are attempting to get a list of the values in the table calling: daveTempDAO.findAll()

    #313513 Reply

    dason
    Member

    Swapna, thank you for your reply.

    We are using Oracle 11G for our database.
    I will append the file DaveTempDAO.java below. If you would prefer it sent to a support email address, just let me know.

    Best,
    Dave

    ===== Begin DaveTempDAO.java ========================
    package com.sampleicefaces3.jpa;

    import java.math.BigDecimal;
    import java.util.Date;
    import java.util.List;
    import java.util.logging.Level;
    import javax.persistence.EntityManager;
    import javax.persistence.Query;

    /**
    * A data access object (DAO) providing persistence and search support for
    * DaveTemp entities. Transaction control of the save(), update() and delete()
    * operations must be handled externally by senders of these methods or must be
    * manually added to each of these methods for data to be persisted to the JPA
    * datastore.
    *
    * @see com.sampleicefaces3.jpa.DaveTemp
    * @author MyEclipse Persistence Tools
    */

    public class DaveTempDAO implements IDaveTempDAO {
    // property constants
    public static final String TEXT = “text”;

    private EntityManager getEntityManager() {
    return EntityManagerHelper.getEntityManager();
    }

    /**
    * Perform an initial save of a previously unsaved DaveTemp entity. All
    * subsequent persist actions of this entity should use the #update()
    * method. This operation must be performed within the a database
    * transaction context for the entity’s data to be permanently saved to the
    * persistence store, i.e., database. This method uses the
    * {@link javax.persistence.EntityManager#persist(Object)
    * EntityManager#persist} operation.
    *
    * <pre>
    * EntityManagerHelper.beginTransaction();
    * DaveTempDAO.save(entity);
    * EntityManagerHelper.commit();
    * </pre>
    *
    * @param entity
    * DaveTemp entity to persist
    * @throws RuntimeException
    * when the operation fails
    */
    public void save(DaveTemp entity) {
    EntityManagerHelper.log(“saving DaveTemp instance”, Level.INFO, null);
    try {
    getEntityManager().persist(entity);
    EntityManagerHelper.log(“save successful”, Level.INFO, null);
    } catch (RuntimeException re) {
    EntityManagerHelper.log(“save failed”, Level.SEVERE, re);
    throw re;
    }
    }

    /**
    * Delete a persistent DaveTemp entity. This operation must be performed
    * within the a database transaction context for the entity’s data to be
    * permanently deleted from the persistence store, i.e., database. This
    * method uses the {@link javax.persistence.EntityManager#remove(Object)
    * EntityManager#delete} operation.
    *
    * <pre>
    * EntityManagerHelper.beginTransaction();
    * DaveTempDAO.delete(entity);
    * EntityManagerHelper.commit();
    * entity = null;
    * </pre>
    *
    * @param entity
    * DaveTemp entity to delete
    * @throws RuntimeException
    * when the operation fails
    */
    public void delete(DaveTemp entity) {
    EntityManagerHelper.log(“deleting DaveTemp instance”, Level.INFO, null);
    try {
    entity = getEntityManager().getReference(DaveTemp.class,
    entity.getId());
    getEntityManager().remove(entity);
    EntityManagerHelper.log(“delete successful”, Level.INFO, null);
    } catch (RuntimeException re) {
    EntityManagerHelper.log(“delete failed”, Level.SEVERE, re);
    throw re;
    }
    }

    /**
    * Persist a previously saved DaveTemp entity and return it or a copy of it
    * to the sender. A copy of the DaveTemp entity parameter is returned when
    * the JPA persistence mechanism has not previously been tracking the
    * updated entity. This operation must be performed within the a database
    * transaction context for the entity’s data to be permanently saved to the
    * persistence store, i.e., database. This method uses the
    * {@link javax.persistence.EntityManager#merge(Object) EntityManager#merge}
    * operation.
    *
    * <pre>
    * EntityManagerHelper.beginTransaction();
    * entity = DaveTempDAO.update(entity);
    * EntityManagerHelper.commit();
    * </pre>
    *
    * @param entity
    * DaveTemp entity to update
    * @return DaveTemp the persisted DaveTemp entity instance, may not be the
    * same
    * @throws RuntimeException
    * if the operation fails
    */
    public DaveTemp update(DaveTemp entity) {
    EntityManagerHelper.log(“updating DaveTemp instance”, Level.INFO, null);
    try {
    DaveTemp result = getEntityManager().merge(entity);
    EntityManagerHelper.log(“update successful”, Level.INFO, null);
    return result;
    } catch (RuntimeException re) {
    EntityManagerHelper.log(“update failed”, Level.SEVERE, re);
    throw re;
    }
    }

    public DaveTemp findById(BigDecimal id) {
    EntityManagerHelper.log(“finding DaveTemp instance with id: ” + id,
    Level.INFO, null);
    try {
    DaveTemp instance = getEntityManager().find(DaveTemp.class, id);
    return instance;
    } catch (RuntimeException re) {
    EntityManagerHelper.log(“find failed”, Level.SEVERE, re);
    throw re;
    }
    }

    /**
    * Find all DaveTemp entities with a specific property value.
    *
    * @param propertyName
    * the name of the DaveTemp property to query
    * @param value
    * the property value to match
    * @return List<DaveTemp> found by query
    */
    @SuppressWarnings(“unchecked”)
    public List<DaveTemp> findByProperty(String propertyName, final Object value) {
    EntityManagerHelper.log(“finding DaveTemp instance with property: ”
    + propertyName + “, value: ” + value, Level.INFO, null);
    try {
    final String queryString = “select model from DaveTemp model where model.”
    + propertyName + “= :propertyValue”;
    Query query = getEntityManager().createQuery(queryString);
    query.setParameter(“propertyValue”, value);
    return query.getResultList();
    } catch (RuntimeException re) {
    EntityManagerHelper.log(“find by property name failed”,
    Level.SEVERE, re);
    throw re;
    }
    }

    public List<DaveTemp> findByText(Object text) {
    return findByProperty(TEXT, text);
    }

    /**
    * Find all DaveTemp entities.
    *
    * @return List<DaveTemp> all DaveTemp entities
    */
    @SuppressWarnings(“unchecked”)
    public List<DaveTemp> findAll() {
    EntityManagerHelper.log(“finding all DaveTemp instances”, Level.INFO,
    null);
    try {
    final String queryString = “select model from DaveTemp model”;
    Query query = getEntityManager().createQuery(queryString);
    return query.getResultList();
    } catch (RuntimeException re) {
    EntityManagerHelper.log(“find all failed”, Level.SEVERE, re);
    throw re;
    }
    }

    }

    #313516 Reply

    dason
    Member

    An update here: I created a brand new project and I am not having the issue with the new project.
    I believe I created both projects in the same way, but obviously there is a difference somewhere.

    For a JPA project, what is the best way to refresh the generated classes like DaveTempDAO.java should the underlying tables change?

    Thank you for your help,
    Dave

    #313522 Reply

    support-swapna
    Moderator

    dason,

    The best way to refresh the generated code is to change the data in the tables.
    It works perfect for me. The DaveTempDAO.java is generated by the reverse engineering process and so something should have gone wrong when you created it.

    If you are able to create a new project and reverse engineer using the same table, I suggest you go ahead with the new project and copy the required files from your old project.

    Let us know how this work for you.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: JPA – findAll() exception: looking for an ID class?

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