Whilst using the MongoDB JDBC driver to connect to MongoDB and read and persist to, collections and documents is fairly simple, I do find it takes me back to the old days of Java database access of having to write a lot of code, to do not very much.
When I moved to EJB 2.0 in the early noughties, I used Container Managed Persistence (CMP) as the persistence solution. This was the precursor to the Java Persistence API.
Before the days of Open Source and the GNU license, with free integrated development environments (IDE) like Eclipse and IntelliJ community edition, you had to pay for your IDE. Borland International was one of the leading software development tool providers of the eighties to the early noughties and had an excellent product for Java Development called JBuilder.
Borland’s JBuilder Professional version included a CMP generator tool, which connected to your SQL database and automatically generated the Java code and the tons of XML to map the relationships between tables. It worked perfectly and reduced days of tedious error-prone Java coding and XML writing to hours. Producing code that worked first-time!
The only problem JBuilder Professional cost £3,000 plus VAT. Even in the heady days of the ‘Dot Com bubble’ that was a week’s fees and I was loathed to pay for my own dev tools. Especially when even the most ridiculous idea was being funded with millions of pounds of venture capital. Also, this was pre IR35 and you didn’t have to prove to anyone you were a legitimate business by using your own laptop and development tools.
Fortunately, my wife was working at a local university at the time and by getting her to purchase it and have it delivered to her place of work I was able to get an Educational discounted version for £895 including VAT. One of best £760 odd I’ve spent. I didn’t advertise the fact I used it and soon became the go-to person for CMP and built a reputation for being able to deliver bug-free EJB ORM database access in an afternoon. This resulted in many renewals.
In 2006 the Java Persistence API specification was released and JPA replaced CMP and I discovered Hibernate which has become my defacto ORM provider since.
The creation of Entity Beans from databases is now a common tool in most IDEs and they create all the Hibernate mapping annotations with no or very little hand-coding.
Roll on to 2018. After a few weeks of hand-coding MongoDB access, I started to investigate if there was an ORM was available forMongoDB and I discovered Hibernate’s Object/Grid Mapper (OGM) for NoSQL databases Your NoSQL datastores. One API.
OGM works perfectly and though I had to hand-code my entities it has significantly reduced the amount of code needed and the ease which I can query and persist my MongoDB documents to collections.