Spring Boot JPA - Entities - spring-boot

Hopefully, you can help me with the following doubts that I have.
So I have an entity called User that has some columns like Nationality, Gender, Professional Status. And I have an entity for each column referred.
I'm looking for the best way to define this.
Should I apply a ManyToMany relationship between those tables? Since Users can have the same Nationality and Gender?
When I try to implement this, Spring is creating a third table automatically and I don't understand the need.
Having the following shouldn't be enough?:
Table User:
id,
name,
id_nationality.
id_gender,
id_professional_status
Table Nationality:
id,
nationality
(etc)
Why Spring is creating another table called user_nationality?
Thanks in advance.

Whenever we are using the ManyToMany relationship in that case a separate table will be created containing both primary keys of the tables involved in the new relationship.

Related

How to establish one to many relationship in Dynamo DB?

I have 2 different JSON Files. One with user details and other with order details. Order details table has a column user_id to match the user ordered for. I have to create a dynamo db table that has the order details nested inside the user details and insert the values from the Json files into this table using a spring-boot app. Can someone help me with this ? Do we have any example code ?
DynamoDB is NOT a relational DB so you can't have relations per se.
However, you have two ways (at least those come to my mind) to achieve what you want.
1) Have two tables: User and Order, the latter with userId field. When you load Order, get your userId and load also a User by the index id.
2) In your User.java you can have field List<Order> orders. Then you need to create Order.java and annotate this class with #DynamoDBDocument. This enables you to have custom objects in your #DynamoDBTable classes. Do not also forget about getters and setters since they are required.

How to create new query method at repository with or without ElasticSearch and Spring Boot?

I have 2 models, one called Employee and another one User,
Employee has one field pointing to User, one to one relationship.
My problem is that i need one query method to find the Employee that has the user with certain id. I need to find the Employee with certain User id.
I know the default query methods: .findOne, .findAll, but i need to create one, alright? how i can do that? i searched a lot but probably i am missing something. I didn't found how to do a query like that.
Thanks

Laravel - Eloquent Models Relations, polymorphic or not?

I have this schema
All the relations here must be one-to-zero/one.
A user can be either an employee or a customer. The user_type ENUM gives me the type so I know where to go from there.
Then an employee can be either basic or a manager. The employee_type discriminator let's me know that.
How am I supposed to build the Eloquent Model relations?
Let's say I have a user that is an employee. I need to get it's common fields from the users table but also need to get common fields from employees table. Do I need to hard code, and know that when user_type=emp I need to select from the employees table? What if I need to add another user type later?
UPDATE
Would it make sense to change my schema into something simpler?
My problem is that by using, as suggested, polymorphic relations I would end up to something like this:
$user = new User::userable()->employable()->...
Would a schema in which I drop the employees table and have employee_managers and employee_basics linked straight to the users table?
this is an polymorphic relationship. but if you want to be easy, you need to fix some things.
in the table employees
- user_id
- employable_id
- employable_type enum(Manager, Basic) # References to the target model
.... this last two are for the polymorphic relation, this is the nomenclature
in the basics and managers table you could delete the user_id field, but you need an id field as increments type
and now in the model Employee you need to make this function
public function employable(){
return $this->morphTo();
}
I hope this works :)

Oracle ADF many-to-many with additional attribute

I'm developing a ADF Fusion Web Application and have some problems with EntityAssociations and ViewLinks.
I have a database table Project with id, name etc. Also I have a table Technology which only contains a id and the name of the technology, for example "ADF".
The relationship between theese two entities is many-to-many. Means one project can have multiple technologies assigned and inverse a technology can be assigned to multiple projects.
This relationship is described trough a join table named Project_Technology. Columns of this table are Project_FK, Technology_FK and Effort. Project_FK and Technology_FK are a composite primary key, Effort is an additional attribute.
Can someone explain me how to map EntityObject and ViewObjects that I can access the Effort, too? "Regular" many-to-many associations aren't that hard to implement but I am really struggling with the additional attribute.
Any help is appreciated. Thanks in advance!
Edit:
I could solve my issues. See answer below for details.
I got it working.
The Problem was the composite primary key on my join tables. It seems like ADF doesn't like them. I put a extra column ID on the join tables and now I can insert values by using the CreateInsert Data Controls.

How to insert into multiple tables with foreign keys in Joomla?

I want to know how to handle mysql tables created with constraints in joomla.
for a example,
theater_table
id , name, description, image, address, tel, fax ,email
theater_facility_table
id, theater_id, facility_id
facility_table
id, name, description, image
Facility table already filled with data and id is the primary key. When creating a theater I am adding facilities to it. I created facility and theater JTables.
Do I have to create theater_facility JTable too?
Using theater Model class how I insert data to theater_facility table. I know I can insert data after theater stored successfully creating and calling storeTheaterFacility() method where it contains insert query to save required information. But I feel it can't be a good method to do so. Please help me to solve this.
Depending on how you implemented the theater - facility relationship, you can handle insering new data in different parts of your code. I mean, if for example your JTable class (the one that loads theaters) is loading/saving the theater-facilities relationship too, then the same class should delete it.
May be you can take a look at other components (for example, com_content, which relates an article to a category, or K2, where you can have multiple tags related to multiple "items"(articles)), so you can take a look on how do these components handle these kind of relationships.
Another important point you shouldn't forget is to update your facility model / table to delete records from the relationship table upon facility deleting.
I hope it helped!

Resources