Comments (13)
Thanks @lukaseder, we will look into it. The whole piece of code is indeed complicated.
from spring-petclinic.
There is a good example of what we should do here: http://stackoverflow.com/questions/6521937/using-spring-jdbc-template-for-populating-results
(proposed by @jnizet)
from spring-petclinic.
Hmm, that all seems very backwards (= too many LoC for little value) to me. With Java 8 (and e.g. jOOQ), I'm sure there's a more functional approach to generating nested collections in non-JPA environments...
from spring-petclinic.
Hi Lukas, sure please feel free to propose something. In general, it's better if we don't have to add an additional dependency in the POM (there are already a lot...)
from spring-petclinic.
You won't like my proposition :) (because I don't think a repository with multiple implementations is a good idea in the first place)
from spring-petclinic.
Sure, please feel free to share. I can't guarantee that it will be suitable but it's always good to discuss.
Cheers,
Michael.
from spring-petclinic.
Sure.
In a JPA / Repository approach, you mostly operate on what a Java developer prefers to work on, i.e. domain objects written in Java. It is natural to navigate those objects in a rather imperative style, i.e. fetching the parent, and then iterating its children, possibly letting the ORM figure out what to fetch eager or lazy (hint: it's mostly wrong by default and needs tuning).
In a SQL approach (JDBC / SpringJDBC / jOOQ / etc.), you would do things very differently. You would think of your data as sets (or bags) of tuples (or rows), which you materialise all at once as required. You wouldn't fetch the pets and visits individually. You'd either:
- Join them.
- Fetch both sets in 2 queries and join them in memory.
- Nest sets via the
MULTISET
operator (unfortunately, not supported in many databases)
In fact, you probably wouldn't even make use of any extra DTOs which are just boilerplate in a SQL context. You'd pass the sets of tuples directly to the UI. If writing back to the database is required (it is here), then you'd probably use an active record pattern as implemented by jOOQ, to store the results that are modified by the UI directly, instead of expressing INSERT
and / or UPDATE
statements.
I'm aware that such a change would be a lot of work, but Spring has a lot of responsibility as well. You guys are an inspiration for a lot of programmers, many of which are not yet very experienced.
My take here is that if you're showing them the JDBC solution as it is now, they will get things wrong. They will think that JPA and JDBC are "similar", instead of learning to think in terms of sets and set theory, as they should when working with SQL...
from spring-petclinic.
Thanks for your feedback.
It makes sense, however the only way we could do that is to remove JDBC from the master branch and have a dedicated JDBC branch (that we will mention clearly on the Petclinic github homepage).
I haven't really used JDBC for years and I'm not the right person to create that branch. In case we would like to go that way, would you be interested to do it?
from spring-petclinic.
In case we would like to go that way, would you be interested to do it?
Only if I can contribute a jOOQ branch, too :) (disclaimer: I work for Data Geekery / jOOQ)
from spring-petclinic.
I'll have to check internally, given that jOOQ is a commercial product. Let me get back to you on that a bit later.
from spring-petclinic.
Note that jOOQ is commercial, but ASL 2.0 (dual-)licensed.
Here's some help for your argumentation showing how other commercial products can add value to Spring :)
https://spring.io/blog/2014/10/01/webinar-building-bootful-uis-with-spring-boot-and-vaadin
from spring-petclinic.
@michaelisvy and @lukaseder, to map the one-to-many relationships between Pet and Visit we may extends the OneToManyResultSetExtractor class provided by the Spring Data Core JDBC Extensions:
http://docs.spring.io/spring-data/jdbc/docs/1.1.0.RELEASE/reference/html/core.support.html#core.support.onetomany
The JdbcVisitRowMapper anonymous class used in the JdbcVisitRepositoryImpl has been reused by the JdbcOwnerRepositoryImpl
Here the corresponding pull request : arey@818529b
from spring-petclinic.
Hi, I think Antoine's solution is good enough for now. I'll close this issue.
from spring-petclinic.
Related Issues (20)
- Duplicate Pet Name on Edit Pet HOT 6
- Sonarcloud with Maven build failed using on Gthub actions HOT 1
- JdbcSQLDataException occurs when passing long name HOT 2
- [Suggestion] Adding messages in Korean HOT 3
- N+1 Queries in Owners endpoint HOT 1
- handle exception HOT 4
- gradle build fails when Docker is not available HOT 6
- Add owner HOT 6
- K HOT 1
- The "Find owner" functionality should be based on the first name, last name, and city, which is only based on last name HOT 1
- Owners should not be allowed to enter duplicate mobile numbers. HOT 3
- Telephone number validation is not user friendly while adding owner HOT 2
- "Confirmation messages are not displayed for 'Add, edit, or update' actions in the application." HOT 1
- For Add new pet functionality selection of "Type" are limited for all types of pet HOT 1
- build failure due to some postgresql issue HOT 1
- Error on linux and java 17 when running ./mvnw package HOT 12
- Unable to format code on gradle HOT 1
- The gradle build failed after adding spring.javaformat HOT 2
- The owner list described in the readme.md file was not found. HOT 2
- Compiling css does not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-petclinic.