0

I have a domain model that corresponds to multiple tables when I use a relational database to design a data store. Now when I create this domain entity, I want to use Spring Data Jpa to write to multiple data tables at once. How to do it?

1.Domain Model:

{
 "id": 2,
 "startTime": "2018-07-09T08:59:08.853Z",
 "endTime": "2018-07-09T08:59:08.853Z",
 "group": 2,
 "entries": [
 {
 "id": 1,
 "target": 90,
 "isFinished": false,
 "name": "俯卧撑",
 "groups": [
 {
 "id": 1,
 "name": "第一组",
 "number": 30
 },
 {
 "id": 2,
 "name": "第一组",
 "number": 30
 }
 ]
 }
 ]
}

2.Data tables:

tb_execise_plan(id, start_time, end_time, group)
tb_execise_entry(id,name,target, is_finished, execise_plan_id, project_id)
tb_execise_entry_group(id,name,number,execise_entry_id)

3.Table relationship:

tb_execise_plan 1:m tb_execise_entry
tb_execise_entry 1:m tb_execise_entry_group
asked Jul 3, 2019 at 8:19
1
  • 1
    Your question as it stands is too broad. Add the code you have so far. Commented Jul 3, 2019 at 8:29

1 Answer 1

0

I recommend you look at Olivier Gierke/Drotbohm presentations and code samples about DDD and Spring data. It's a different approach than JHipster's entity generator which is about one JPA repository per entity.

But starting from JHipster generated repositories, you could aggregate your entities within a @Service annotated class using @Transactional annotated methods.

You can find an example of this approach in your JHipster generated project with UserService class which aggregates a User and its Authorities.

answered Jul 3, 2019 at 14:47
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.