What I want to do is to create a full Spring WebMVC CRUD API from database tables/Hibernate JPA entities, into an existing Maven Web Project.
What I want generate, to be precise:
Spring WebMVC controller (mapping&implementation)
The JPA entity (if not given) - ofc. using the standard generation built in to most IDEs
Spring Data JPA repository
Optionally modifying some other files (f.e. adding the entity to existing persistence.xml)
Is there a project for this?
What would be the best way to create something like this?
What I had thought about:
Standalone Java APP
Maven subgenerators
Eclipse plugin
Standard code generation methods (f.e. Acceleo plugin)
What would you suggest?
Partial Answer :
If you can generate JPA entities and Spring Data JPA Repositories, you can use Spring Data REST to expose the repositories as a full CRUD REST API.
Although Spring Roo will generate a CRUD application for you, however the code it generates is outdated. If I where starting a new project, I would definitely stay away from it (at least until a new version is released).
I suggest you take a look at JHipster which is a Yeoman that will generate a CRUD application using some of pretty hot tech (like Spring Boot, AngularJS etc.)
Besides the novelty factor of the generated code, another great feature of the project is that it is extremely active as is evident from the releases
The response is probably in this tutorial :
https://sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa
You can take a look at crud-rest-gen project which explains how to use the crud-maven-plugin to generate :
the CRUD Rest API
the documentation of the API
the HTML5/AngularJS CRUD Administration UI
the Rest API for retrieving audit information and associated unit tests if you use Hibernate Envers to audit your entities
All you have to provide is the data model containing the JPA entities.
Spring-roo (link) have these features, and if you want you can remove spring-roo from your project and remains a java-spring project.
Sample from link :
roo> hint
roo> project --topLevelPackage com.foo
roo> jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
roo> entity jpa --class ~.Timer --testAutomatically
roo> field string --fieldName message --notNull
roo> hint web mvc
roo> web mvc setup
roo> web mvc all --package ~.web
roo> selenium test --controller ~.web.TimerController
roo> web gwt setup
roo> web gwt all --proxyPackage ~.client.proxy --requestPackage ~.client.request
roo> perform tests
roo> quit
As you can see : create the project, setup jpa provider, create Entity, create MVC Controller, the Tests and some GWT setup.
A Yeoman generator for generating Microservices with SpringBoot in Hexagonal Architecture
https://www.npmjs.com/package/generator-springboot-hexagonal
Related
I am just starting with Spring boot Web Applications, and I am in this point now I need to issue notification in the app ecosystem after CRUD Operation in database (I am using MySQL)
How can I set up a listener and based on the operation to create a new notification. From my search, I land on #EntityListeners(AuditTrailListener.class) but not sure how to use it, I will be happy to share with me some examples or to redirect me to the right place to see how to set up that kind of listener.
Here's a collection of links which are providing some details about #EntityListeners with JPA in Spring Boot webapplications :
JPA Entity Lifecycle Events
A gist of a php-coder
Spring Data JPA Entity Auditing using EntityListeners
Spring JPA Auditing in Official Documentation
StackOverflow: How to use an #Autowired #EntityListener
StackOverflow: How to inject a dependency into a JPA #EntityListener
I think you'll have common paths to seek the information you need with all that links. And maybe other people will help you more.
Can anyone please help me on how to integrate Olingo (Odata) in a Springboot Java Appln.
I'm pretty new to Spring boot and have implemented one project and wanted it to convert to Oling (Odata).
I have gone through various resources but with a bunch of different approaches not sure how to do it the correct way.
Please let me know if some has worked on it and can guide me.
link to the project on which I applied spring-boot.
If you are trying to integrate OlingoJPA there are a couple of things you will have to do
Implement JPAServiceFactory and initializeODataJPAContext, basically this is about defining the persistence unit and entity manager
Then you can create a Spring Boot Configuration to mount your OData endpoint and initialize the EntityManagerFactory
Then you can point to your database here
An finally you can define the JPA entities you want your service to expose
The full Spring Boot + JPA project sample is located Github. Feel free to go though it, raise an issue or submit a Pull request for impalements
I'm working on a spring boot application using spring data jpa at Spring Tool Suite IDE. I need to create entity classes from database but I couldn't find any answer to how to do it.
I saw an answer about adding JPA Facet adding and using it. But I couldn't add JPA Facet because my application is maven web , not jee application.
Mapping from db table -> entity:
Eclipse:
Make an empty JPA Project, set data sources and use JPA Tools > Generate entities from Tables. Then copy-paste model classes to your project.
IntelliJ:
Install plugin JPA Buddy and make a reverse engineering:
Reverse engineering video
Netbeans:
How to
If you know other ways to generate entities, please tell us.
You don't create entity classes from database. You create models to map your table and its relationships with other tables.
Application Properties to configure JPA mapping.
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
Map your classes to a table.
https://www.vogella.com/tutorials/JavaPersistenceAPI/article.html#simple
I have two projects
ProjectA --> 'Spring Boot JPA based Java` project
ProjectB --> General 'Java' project
My Database is MySQL Server
My ProjectA is a web project so from a webpage I was able to get a lot of data inserted into multiple tables without any insert queries. This is because it's a JPA project and it was super easy.
Now I want to access the same data from the same database in a few Java classes in my ProjectB. I don't want to convert this into a Spring Boot project and make it more complex just to read data from two tables.
On the other hand I really don't want to use JDBC Connectors and process ResultSet etc. I like the way how annotations were used in Spring Boot JPA project to write and read data from the database.
What options do I have here?
You can use spring's JDBCTemplate or HibernateTemplate to minimize your code.
I'm new to Roo (and Java in general). I'm following Hantsy's tutorial and am running in to problems trying to create the service.
roo> service --entity ~.model.Conference --interface ~.service.ConferenceService
Command 'service --entity ~.model.Conference --interface ~.service.ConferenceService' not found (for assistance press TAB or type "hint" then hit ENTER)
addon search --requiresCommand "service" found no matches
Any ideas on why?
I'm using Roo 1.2.4 Release (no STS)
While following "Spring in Action" I encountered the same problem with Roo 1.2.4.
Try using roo> service type instead of just roo> service.
I had the same problem. The only thing I could find is this:
If you would like to use a services layer, since release 1.2.0 Roo
offers automatic service layer integration for your application.
Please refer to the service layer section in the application layering
chapter for further details.
I just built my application without running that command. That is the problem with most of the tutorials I am finding, they are out of date.
I have the same problem with Roo 1.2.4. However it works with Roo 1.2.3. So you can create the service layer in 1.2.3 and the rest in 1.2.4. It worked for me.
According to Roo 1.2.4 documentation, that command should work.