facebook

adding queries

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

    Douglas M Hurst
    Participant

    My question is how can I add a specific query to what’s been generated by reverse JPA engineering without having it overwritten if I have to redo the reverse JPA engineering?

    Instead of just the reverse engineering generated code findAll() below, I want to return specific records based on the time difference between the current date/time and what’s in a date/time field in my database.

    I think I could add the code in a manner consistent with what’s been generated, but I fear it would be wiped out.

    IMonitorScheduleDAO.java
    /**
    * Find all MonitorSchedule entities.
    *
    * @return List<MonitorSchedule> all MonitorSchedule entities
    */
    public List<MonitorSchedule> findAll();

    IMonitorScheduleDAO.java

    /**
    * Find all MonitorSchedule entities.
    *
    * @return List<MonitorSchedule> all MonitorSchedule entities
    */
    @SuppressWarnings(“unchecked”)
    public List<MonitorSchedule> findAll() {
    logger.info(“finding all MonitorSchedule instances”);
    try {
    final String queryString = “select model from MonitorSchedule model”;
    return getJpaTemplate().executeFind(new JpaCallback() {
    public Object doInJpa(EntityManager em)
    throws PersistenceException {
    Query query = em.createQuery(queryString);
    return query.getResultList();
    }
    });
    } catch (RuntimeException re) {
    logger.error(“find all failed”, re);
    throw re;
    }
    }

    #286532 Reply

    Brian Fernandes
    Moderator

    Douglas,

    Once the DAOs are generated you could choose not to generate them by turning the “Java Data Access Generation” off for subsequent RE passes.

    If that is not an option, please see section 5.5 of our Hibernate tutorial for details on how to use templates to modify the RE process (applies to JPA as well). You need to modify the dao/daohome.vm file to make changes to the generated DAO.

    Please let us know if you require further assistance.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: adding queries

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