Well, if you just want a stand-alone application without web interfacing, that's no problem, although this isn't the forum for details.
Basically, a stand-alone app can do anything it wants. You can write brute-force code to use
JDBC, use an ORM such as JPA/Hibernate (done that many times), you can build the app on the Spring Framework, use OSGi to manage it,
etc., etc., etc.
I did something several years ago that could run up to 8 hours. It processed about 3 million records against US Government watch lists and had to run daily. There were optimizations in it, but about once a week on average, a full run, lasting about 8 hours would kick in. At the time, the most appropriate technology for me was to do this as a stand-alone Java RMI application. The application was driven via RMI method calls from a web application. The web app also shared the database with this stand-alone app so that the users could review the results.
I'll be doing something similar again this week on a smaller scale. Since the batch run shouldn't exceed about 5 minutes, I'll probably employ recent improvements to JEE that support batch operations in webapps rather than write an external batch program. If it was expected to run longer, I'd outsource it to an external app, though, since I don't like my web applications "held hostage" to work in progress if we need to do an emergency update to the applications or something.