- This topic has 1 reply, 2 voices, and was last updated 16 years, 4 months ago by Brian Fernandes.
-
AuthorPosts
-
Douglas M HurstParticipantMy 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;
}
}
Brian FernandesModeratorDouglas,
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.
-
AuthorPosts