# Design the Initial ERD of ScholarX

**URL:** <https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72>\
**Category:** ScholarX\
**Created:** [May 13, 2020, 2:13am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72 "2020-05-13T02:13:36Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![akshika47](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/akshika47/32/993_2.png) [@akshika47](https://sef.discourse.group/u/akshika47)\
**Post date:** [July 28, 2020, 2:12pm UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/21 "2020-07-28T14:12:19Z")

</div>

Yes. We can preload them with a standard set of questions as well.

---

<div class="post-metadata">

**Author:** ![Gravewalker](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gravewalker/32/12_2.png) [@Gravewalker](https://sef.discourse.group/u/Gravewalker)\
**Post date:** [July 28, 2020, 2:14pm UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/22 "2020-07-28T14:14:26Z")

</div>

Then I guess we have to keep the link of the doc in the mentee table. Just to clarify, a user would have to create multiple docs to apply to multiple mentors right?

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [July 31, 2020, 5:44am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/23 "2020-07-31T05:44:10Z")

</div>

## ERD design call 2 - finalizing ERD

When: 2020-07-30T12:30:00Z → 2020-07-30T14:00:00Z

Where:

> **[Meet](https://meet.google.com/unsupported?meetingCode=amr-cvhx-ypt&ref=https:%2F%2Fmeet.google.com%2Famr-cvhx-ypt)**
>
> Real-time meetings by Google. Using your browser, share your video, desktop, and presentations with teammates and customers.

Attendees: @jaye @Gravewalker @Gimhan_minion @anjisvj @piumal1999 @YohanAvishke

Diagram:

 ![ScholarX ERD](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/ba4f254f86844ead8427eaf32261eee6d1bde784.jpeg)

Editable file:

> **[ScholarX ERD.drawio](https://drive.google.com/file/d/1L7OXu9KQkxEuWSp-ke7vqSQlS9xaFpPY/view)**
>
> Google Drive file.

GitHub Project board:

> **[Build software better, together](https://github.com/orgs/sef-global/projects/3?add_cards_query=is:open)**
>
> GitHub is where people build software. More than 50 million people use GitHub to discover, fork, and contribute to over 100 million projects.

---

<div class="post-metadata">

**Author:** ![shyamal](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@shyamal](https://sef.discourse.group/u/shyamal)\
**Post date:** [July 31, 2020, 7:37am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/24 "2020-07-31T07:37:25Z")

</div>

Good job team!

Can’t mentee join a program before selecting a mentor?

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [July 31, 2020, 8:33am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/25 "2020-07-31T08:33:45Z")

</div>

Hi @shyamal, no users have to select a mentor inorder to apply as a mentee

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [August 7, 2020, 7:27am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/26 "2020-08-07T07:27:32Z")

</div>

Added changes due to discussions in the [thread](https://sef.discourse.group/t/designing-the-class-diagram-of-scholarx/151/11).

 ![ScholarX ERD](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/1a941405c794db94820bd30ed1de22cd4b4610c5.jpeg)

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [August 8, 2020, 2:37pm UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/27 "2020-08-08T14:37:19Z")

</div>

Updated diagram with newly added `mentee - program` relationship

 ![ScholarX ERD](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/8744113db7d18a535f596a308a8a62b25806d7a3.jpeg)

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [August 9, 2020, 8:03am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/28 "2020-08-09T08:03:40Z")

</div>

Thanks @YohanAvishke,

Could you please come up with a small comparison on “Creating the DB tables manually” vs “Letting Hibernate to generate the tables”?

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [August 10, 2020, 7:58am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/29 "2020-08-10T07:58:12Z")

</div>

Hi @YohanAvishke,  
Where are we up to now on this task?

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [August 10, 2020, 9:18am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/30 "2020-08-10T09:18:37Z")

</div>

Hi, I did some research on finding the best approach for database initialization and data management.  
SpringBoot recommends any of the following ways to initialize the database,

- JPA, Hibernate, basic SQL scripts  
There is no logical difference between these approaches. And the approach that one should use completely depend on the technologies of the project itself.

But however, since the main reason we are trying to use basic SQL scripts is the issue with Cascading, I did some further digging to check if it’s recommended to use the Cascading on the script itself.  
And the approach is not recommended because

> Hibernate doesn’t know which records the cascading operation on the database removes. It can’t remove any entity that maps one of the removed records from the 1st or 2nd level cache. Due to this, you are at a high risk that your caches contain outdated information (records that no longer exist).

In other words, the SpringBoot database cache can get invalidated and we will be forced not to use the `EntityManager `.

So the best approach would be as follows,

- Let the database initialization through JPA Entities without adding Cascading to any of the `to many` relationships.
- When a bulk removal is needed(Eg: Removing children of a parent) write native SQL scripts in the Repository to provide the functionality.

This approach will solve the above mentioned caching problem and the following 2 problems,

1. When using JPA delete with Cascade for a `to many` relationships, a huge number of SQL scripts will be executed.
2. When using JPA delete with Cascade for a `many to many` relationships, a chain removal might occur and might end up removing all the data.

References:  
i. [https://docs.spring.io/spring-boot/docs/2.3.2.RELEASE/reference/html/howto.html#howto-database-initialization](https://docs.spring.io/spring-boot/docs/2.3.2.RELEASE/reference/html/howto.html#howto-database-initialization)  
ii. [https://thorben-janssen.com/avoid-cascadetype-delete-many-assocations/](https://thorben-janssen.com/avoid-cascadetype-delete-many-assocations/)

WDYT about the above approach?

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [August 10, 2020, 1:20pm UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/31 "2020-08-10T13:20:40Z")

</div>

Thank you so much for the very informative comparison @YohanAvishke!

Seems letting Hibernate to generate tables might be a good practice.

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [October 22, 2020, 6:12am UTC](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72/32 "2020-10-22T06:12:22Z")

</div>

### Changes requested in the [thread](https://sef.discourse.group/t/schoalrx-platform-v1-progress-evaluation/192/2)

[https://drive.google.com/file/d/1L7OXu9KQkxEuWSp-ke7vqSQlS9xaFpPY/view](https://drive.google.com/file/d/1L7OXu9KQkxEuWSp-ke7vqSQlS9xaFpPY/view)

 ![ScholarX ERD](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/908c28362a54743d87e524f728c6fd189252f38c.png)

**Reasoning for the changes:**

> [@Creating a view for Apply as a Mentor](https://sef.discourse.group/t/creating-a-view-for-apply-as-a-mentor/193/2):
>
> Later after the mid-week call we decided that using steps is not needed because there are only 2 questions for mentor. So we thought to add 2 text areas for mentor to answer. Therefore during the call @jaye created the below wire-frame to understand about further development. This is the new wireframe According to the above wireframe I changed the mentor application view as below. Please let me know your thoughts hugs

[Previous page](https://sef.discourse.group/t/design-the-initial-erd-of-scholarx/72.md?page=1)
