Spring Api and Mongo DB - spring

we currently have a REST Api and it is connecting to Oracle, through Hibernate.
We are contemplating the idea of experimenting using MongoDB as a the database, and I was wondering if people could share their experience.
Obviously it won't be a simple switch. The way we persist and retrieve needs to change. Hibernate might no longer be required.
Is the best practice to design such that the Documents are stored as the Api response should be; it no transformation required?
Thanks for sharing your experience.
Cheers
Kris

Related

Is there a way to use Panache in Quarkus in a "standalone way"

I use Quarkus for my backend application since few months and today i have a specific use case :
I have a lot of database (sqlite) and it's not possible for me to specify all of this database in the application.propertie. So, i wrote some code, using agroal, to access to my database. The thing is that, if I do that, i am wondering how i can mix that with panache ?
Panache & panache entity is really nice and easy to use, but in my case, i'm a little bit on the edge of the framework and i can't find a good way to do what i need.
By managing my databases by myself and agroal as a pool, it's "low level" and i can't find how to use the power of Panache instead of writing all SQL query by hand.
Thank'a a lot.

What is the best way to use Spring and ElasticSearch?

I have to implement some application by using springframework.
All i have to do is just select from repository (no RDBMS, maybe lucene or elastic search core) and Display some view pages for customers. that is not save or update but read.
What is the best way to select for repositories in spring framework ?
You can use spring-data-elasticsearch which is the Spring Data implementation for ElasticSearch.
In order to get started, you may like to refer to https://www.mkyong.com/spring-boot/spring-boot-spring-data-elasticsearch-example/ which explains the integration with an example. Although it is a bit old but provide you with enough information to get it working.

How to make Spring Hibernate Application enterprise ready?

So, I have my application based on spring and hibernate. The user produces some data (in my case the data is kind of development itself) which is persisted by hibernate.
But for now this won't be accepted by large enterprises. They want to have a development enviroment, a test environment and a production. What I need to implement is a way to deploy data from one environment to another.
To be clear: I am not asking about deploying the application, but its data.
Are there best practices to implement this feature?
To maintain DDL and use same across various environments use liquibase or flyaway which also integrates with seamlessly with spring.
If you want DML to be migrated then vendor specific data migration can be used.
I think you are mostly looking at DDL only so either of above is better solution

When to use default Spring Data REST behavior?

I recently worked on a project which uses Spring Data REST with Spring Boot. While it is GREAT to harness the power of Spring Data REST and build a powerful web service in no time, I have come to regret one thing: how tightly coupled the "presentation" layer (JSON returns) is to the underlying data structure.
Sure, I have used Projections and ResourceProcessors to manipulate the JSON, but that still does not completely sever ties with the database structure.
I want to introduce Controllers to the project, to integrate some of the "old" ways of building a web service in Spring. But how should I draw the line? I don't want to eradicate Spring Data REST from my project.
I am sure many of you have faced similar decisions, so any advice would be most appreciated!

Hibernate with MongoDB

I'm looking for resources showing how to integrate MongoDB with Hibernate (preferably from within spring) so that I can switch between a RDBMS and a NoSql alternative: does anyone have experience doing this?
You can't easily do this. The point of Hibernate is to map Java Objects to a relational database. Although Hibernate abstracts a lot of details away you still need to understand how relational databases work with things such as foreign and primary keys, and the performance implications of queries you run. MongoDB requires an entire different way of designing your database focusing on objects instead of columns and tables. while you may be able to create a Hibernate dialect for MongoDB creating a design that would work on both a relational database and a NoSql database will give you a design that works poorly on both.
What about Hibernate OGM? It provides JPA for No-SQL databases.
Migration would be easier if you use Spring MongoTemplate (similar to HibernateTemplate). Among its features is support for JPA annotations (although, I'm not sure to what extent).
See more: http://www.springsource.org/spring-data/mongodb
You'll need the following:
Add spring-data-mongodb JAR to your project (available in maven
central).
Add mongo-java-driver JAR to your project (available in
maven central).
Use the provided MongoTemplate class in a similar
manner to HibernateTemplate. E.g.:
mongoTemplate.findById(id, MyClass.class);
mongoTemplate.insert(myObject);
Here's a concrete example with code: use-spring-and-hibernate-with-mongodb
If you are using Java then you can use Hibernate OGM it provides Java Persistence support for NoSQL databases.
For more details visit http://hibernate.org/ogm/
There is nice work done earlier as:
http://pragmaticintegrator.wordpress.com/2011/07/14/use-spring-and-hibernate-with-mongodb/
http://pragmaticintegrator.wordpress.com/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/#comments
refer to these links. it will be helpful to you.
There is also kundera, which uses JPA-annotations to read/write your object from/to a mongodb. If you ara familiar with hibernate, it should be quite straightformard to use.
I recently tried Morphia, which takes the same approach, but with its own annotations.
It works fine
May this blog helps: http://drorbr.blogspot.com/2010/02/migrating-springhibernate-application.html
Here Dror Bereznitsky describes nicely how to integrate a sping/hibernate based solution with mongodb.
For the sake of completeness, PlayORM also supports MongoDB now. PlayORM is an object NoSQL mapping solution so you can write POJO’s and let it deal with all the details of marshalling/unmarshalling to MongoDB. Visit its documentation here
I think Hibernate provides desired functionality. Take a look at this, found on their official website:
Mixing several NoSQL datastores in one application, e.g. use Neo4j for your friendship graph and MongoDB for your blog posts. Or mix NoSQL and relational databases.
reference
Well just to give you an example, I am doing somehting simmilar. In ColdFusion, Hibernate is integrated and in order to save your Hibernate Object, you hvae to do EntitySave(Obj). However what we have done is build the Orm object, and then use a mongoDB Coldfusion component and just save the object by going mongo.Save(obj,collectionName).

Resources