Spring Framework Saving Data to Multiple Tables - spring

Newbie here...
I'm working on a Spring MVC app and their JDBC api for data access. How would I go about saving data to multiple tables? The insertion needs to be such that if there's an error or something goes wrong, nothing gets inserted and rolled-back. Would this be Spring's transaction support? If so, the official documentation for transaction support is very confusing to me. Does anyone have a good source for learning how to do that?
I'm using Spring 3.1, Oracle 11g, and Tomcat 6.0

Yes, spring supports transaction. You can use DataSourceTransactionManager to configure your bean.IF you find xml mapping confusing you can use annotation #Transactional. Spring's annotation support for transactions are really simple. Spring in Action book has examples for transaction management.

Related

Access Amazon QLDB in Spring boot application

is there a way to access Amazon QLDB as a repository in spring boot applications like MongoDB?
There isn't a library yet that integrates QLDB with spring boot.
I started to look at building exactly what you suggest, I even contacted the lead of spring data to look at adding this (I haven’t raised the ticket yet), however the CrudRepository interface provided enough integration for the demo applications that we have built with Spring Boot. One of the issues that i had when trying to create the Repository was the mapping of fields from the java objects into the partiql fields without explicit knowledge of what was changing.
QLDB does not have a jdbc driver anymore so it is now a proprietary driver which also uses partiql over sql, there could be some further issues getting this to work as a full blown repository in spring boot due to the inner reliance on sql in spring data .

Spring boot JPA without Spring data

I'm gradually introducing Spring Boot to a Spring JPA project. My intent was to first introduce Spring Boot, than at some later stage Spring Data, but I was not able to find any examples (nor a suitable starter) that uses Spring Boot + JPA without Spring Data.
How come? Is there any benefit of introducing Spring Boot to Spring JPA project, without Spring Data, or does it make sense only with Spring Data in place.
Any article link or example code would be helpfull and appreciated, thanks
More context
I'm working with a live project so every change introduces risk. We're discussing of moving from XML to JAVA based configuration, and I'm advocating adopting Spring Boot at a same time, but I lack persuasive selling points.
Personally, I want to include Spring Boot on all layers to boost future productivity, but I need to argue better the direct immediate benefits of using it in our Service/DAO module which is at the moment based on Spring/JPA/Hibernate with the good old manual CRUD implementations.
So I need selling points for using Spring Boot on a persistence layer, but ones that span beyond Spring Data (e.g. configuration gains, maintenance, testing...anything)
As folks have said above, there is no Spring Boot JPA. It's either Spring Boot Data JPA, or JPA on its own.
The immediate benefits that I could think of:
With Spring Data JPA you don't write the Dao layer. For all CRUD operations, the CrudRepository interface gives you all you need. When that is not enough, all you have to use is the #Query annotation to fine-tune your SQLs
Configuration by convention. For example, with Spring Boot, just having the H2 dependency in the classpath gets Spring to use the H2 in-memory database, gives you Datasource configuration and transaction management (only at the JPA repository level) by default
Ability to create micro-services. With Spring Boot, you can create micro services that can be deployed and run on a number of boxes with java -jar ...
You can enable annotation-based transaction with one simple annotation: #EnableTransactionManagement
Java configuration over XML. This advantage is not to be underestimated
A lot less code (the DAO layer) means also a lot less maintenance
The native ability to provide a RESTful API around data: https://spring.io/guides/gs/accessing-data-rest/
It all depends where your company is heading for. If they want to deliver business value faster and move towards more a DevOps operating model, then the above advantages should be enough selling points for any organisation
Spring wiht JPA (for example Hibernate) but without Spring-Data-Jpa means that you direct interact with the JPA Entity manager and. Typical you use it to implement your own DAO from it and use the #Respository annotation.
#Respository
public class UserDao {
#PersistenceContext EntityManager em;
public User findUserByLogin(Sting login) {
....
}
}
Even if there is no starter project, you could use a Spring-Data-JPA project, and implement the Repository in this old fashion style. (And then you could show how simple it become when you just write Spring-Data-JPA interfaces)
As far as I known, spring-boot means more convenient not any independent business feature.
In other words, spring-boot helps you to start, configure your application in some automatically way. But you can do that without spring-boot with your own specific configuration.
So, you are going to use spring-boot in your application means you are going to use spring-boot's auto configuration feature with your original application.
Actually, Spring JPA implemented in spring-data-jpa is what you are looking for not spring-boot. Of course, spring-boot can simplify your work dramatically.

spring persistence xml

What is the difference between:
persistenc.xml can be configured with hibernate properties OR Javax.persistence properties.
What scenarios would you use either one.
I tried using javax.persistence but my spring app would not work.. changed it to hibernate and it started working.
javax.persistence is the standard. Hibernate is an implementation. If you are completely sure that your DB layer will always be handled by Hibernate, go ahead and configure using Hibernate. If not, use javax.persistence, so that you could change your DB layer in the future.

Spring Hibernate Connection through AOP standalone application

I am trying to develop Annotation based Spring Hibernate standalone application to connect to DB. I've gone through the some blogs and wondered like we should not make use of hibernateTemplate becoz coupling your application tightly to the spring framework. For this reason, Spring recommends that HibernateTemplate no longer be used.Further more my requirement is changed to Spring Hibernate with AOP using Declarative Transaction management.I am new to AOP concepts. Can any one please give an example on Spring Hibernate Connection through AOP. That would be a great help to me.
Thanks in advance.
If you are looking for exemples of project structures, you may want to use maven archetypes which provide you an already working Spring + Hibernate or Spring + JPA configuration.
They may provide you also a web layer (or not) but you can remove it if you want.
To try that, install maven and type:
mvn archetype:generate
By the way, I don't think using HibernateTemplate is a big deal. Many people still use it. But you'd better inject the Hibernate session factory and use contextual sessions with getCurrentSession()
I'd use JPA instead of plain Hibernate. You can of course use Hibernate as a provider. I guess that you know how to run Spring container in standalone application. Just follow the steps from documentation here. Use LocalContainerEntityManagerFactoryBean. Then read about transaction management.
There is a new feature that lets you start JPA without persistence.xml file. Read here.
If you still want to use plain Hibernate follow the docs.

Spring JDBCTemplate on Seam-based app

When manual SQL is required (JDBC API with pre-written queries), what is the best approach in a Seam-based application ?
In Seam Documentation, use of Spring bridge to inject a Spring JDBCTemplate is defined as the most complex to setup, but the easiest for development.
Do you agree with that ?
You could also use EntityManagers createNativeQuery() method. So you don't need spring perform native queries in a seam application.

Resources