DEV Community

Roberto Conte Rosito
Roberto Conte Rosito

Posted on • Originally published at blog.robertoconterosito.it on

Setup Spring Boot with JPA and MySQL

Welcome back to my dev notes!

Few things that I’ve to remember next time I need to setup a Spring Boot project with JPA and MySQL:

  • Add the following dependencies to your pom.xml:
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
</dependency>

Enter fullscreen mode Exit fullscreen mode
  • Add the following properties to your application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

Enter fullscreen mode Exit fullscreen mode
  • Create your model using @Entity and @Id annotations:
@Entity
public class User {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;
 private String name;
 private String email;
 private String password;
 // getters and setters
}

Enter fullscreen mode Exit fullscreen mode
  • Create your repository extending JpaRepository adding @Repository annotation:
@Repository
public interface UserRepository extends JpaRepository<User, Long> {}

Enter fullscreen mode Exit fullscreen mode

Now you are ready to @Autowired your repository and use it in your services/controllers.

That’s all for today, see you next time!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free