Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between @Entity and @Document in spring boot?

Can you use both annotations on your database tables?

id, just like some clarification on there differences. thank you

like image 719
java beginner Avatar asked Nov 02 '25 03:11

java beginner


1 Answers

@Entity is used to map a class to a relational database, it represents a database table.

@Document is used to map a class to noSQL database (specifically mongoDB), it represents a MongoDB documents.

You can use both JPA or MongoRepository if you are using both databases by creating different entities and repositories for each database.

I recommend you to have a look at spring documentation (https://docs.spring.io/spring-data/jpa/docs/current/reference/html/)

like image 193
Codepressed Avatar answered Nov 03 '25 22:11

Codepressed