#DBRef annotation only storing ref to _id of other table - spring-boot

I have a user table and role table and in the user table I am referencing the Role table to store the full role document as an array. But upon creating a user with a role and querying it in Mongo I am only seeing this:
roles" : [
DBRef("roles", ObjectId("63e4c8edb1d6b11e636809f6"))
],
But in reality I want to see the full Mongo document of it. I am using spring boot 2.7.8

Related

Is using #Entity annotation in Spring boot JPA creates a table?

BACKGROUND
I am new to developing API in spring boot. I have this project wherein it is connected to an Oracle DB and PostgreSQL. The Oracle DB already have an existing tables and I need to fetch some data from multiple tables and send it back as a response. The Postgres DB is where I store the users data and other some data that doesn't need to be stored in the Oracle DB. I am currently using native queries.
The Account is an entity wherein I just marked one of the columns as the #Id (It is actually not an Id but it is unique for all accounts):
#Entity
#Data
#AllArgsConstructor
#NoArgsConstructor
#Builder
public class Account {
#Id
private String sampleProperty1;
private String sampleProperty2;
private String sampleProperty3;
private String sampleProperty4;
private String sampleProperty5;
}
Now I have a repository interface:
public interface IAccountRepository extends JpaRepository<Account, String> {
#Query(value = "SELECT * FROM TABLE(SAMPLE_PACKAGE.SAMPLE_FUNC_GETACCOUNTS(?1))", nativeQuery = true)
List<Account> getAllAccountsByClientNumber(String clientNumber);
}
I was able to fetch the data and JPA mapped the columns automatically to my entity. Basically I am creating an Entity (Spring boot) for the data in my Oracle DB where the only purpose of it is to map the data and send it back to the user.
QUESTIONS
Will this approach create a table in my Oracle DB? I checked the Oracle DB and there is no table. But I'm worried it might somehow create a table of ACCOUNT in the oracle DB when it is on production. If this might happen, how can I prevent it?
This scenario also applies to other functionality like fetching transaction history, creating transaction, updating the Account data that are all in the Oracle DB. Am I doing it just right or there is a better option?
Is creating an Entity without a corresponding table have a drawback in Spring boot?
Note
I know you might say that I should just use the Oracle DB and create entities based on the existing tables. But in the future of the API, it will not have a connection with the Oracle DB. I already tried using projections it was also good, but I still needed to create a Response model and mapped it then send it back to user and creating a unit tests using the projection is pretty long and it sucks haha
You can set the following property:
spring.jpa.hibernate.ddl-auto=update
update will update your database if database tables are already created and will create if database tables are not created.

How to connect class User of JHipster with an existing class containg users credentials

I have a project generated with Jhipster(Spring Boot) and I have an existing database with a table "Utilisateur" and this one contains already "username" and "password" and other fields.. I would like to use authenticate function of JHipster so that the existing users (in table Utilisateur) can access to thier accounts but I don't know how to do it since authenticate function works with User class that also has "username" and "password" fields..
I searched here https://www.jhipster.tech/user-entity/ but doing it with inheritance (Utilisateur extends User) implies to add User fields to Utilisateur table and I don't have to add new columns to Utilisateur table.
Please any simple solution to solve this problem
Just modify manually the generated code: change the name of table in User class and change the Liquibase migration of User table in src/main/resources/config/liquibase/changelog/00000000000000_initial_schema.xml.
As you already have a Utilisateur table, I would modify Liquibase migration to replace User table by Utilisateur table. I would not rename the mapped entity as Utilisateur, I would keep it named as User so that I don't have to change all code dealing with authentication.
You should also change test data in users.csv so that it matches the structure of your Utilisateur table.

How to disable creation of kv_json JSON field in Oracle NoSql from spring data jpa, and have all fields in entity as key-value pairs?

Here is the spring data oracle nosql persistence model link:
https://docs.oracle.com/en/database/other-databases/nosql-database/20.3/java-driver-table/persistence-model.html
In the Student entity shown in the image/from link, firstName and lastName fields are not getting created as key-value fields, instead, a kv_json JSON field is created and the firstName and lastName fields schema is present in the kv_json field.
As per the documentation,
the fields apart from the primary key will be mapped to a single JSON
field named kv_json
I want to disable this feature of having kv_json JSON filed and want to have all java fields in the entity as columns directly like the id field in the oracle NoSQL table.
Is there any solution to achieve this?
For a basic reference of Spring with Oracle NoSql: https://github.com/oracle/nosql-spring-sdk
Yes. This is confirmed. There is no way to do the mapping to a fixed schema or an existing schema. Please refer to this link with the new documentation for more information: https://github.com/oracle/nosql-spring-sdk/blob/main/README.md

OneToMany and ManyToOne mapping in spring boot

I need to create a group with multiple users (which are taken from user table) and single employee for every group in spring boot using rest api.
It means I want to perform OneToMany mapping between group to users and ManyToOne mapping between group and employee.
In fact 1 employee can handle more than one group, and all these data I want in a single table.

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.

Resources