DEV Community

Karan Sahani
Karan Sahani

Posted on

Spring Boot CRUD Generator v1.1.0 โ€” JPA Relationships, Done Right

๐Ÿ”— Plugin link: https://plugins.jetbrains.com/plugin/29476-spring-boot-crud-generator

I shipped an update to my IntelliJ plugin that fixes something subtle but critical โ€” the way generated Spring Boot code handles JPA relationships.

The plugin has crossed 1200+ downloads, and the feedback pattern was clear:

Everything works fineโ€ฆ until you add relationships.


โŒ The Real Problems

1. LazyInitializationException at runtime

Generated mappers were doing this:

entity.getPosts().stream()...
Enter fullscreen mode Exit fullscreen mode

Works in tests.
Breaks in production (outside transaction scope).


2. null IDs in API responses

DTO generator was skipping id completely.

So every response looked like:

{ "id": null, "name": "java" }
Enter fullscreen mode Exit fullscreen mode

Which makes your APIโ€ฆ basically unusable.


3. Mapper calling setters that didnโ€™t exist

Inverse @OneToMany relationships were not generated in DTOs.

Result:

  • Mapper tries โ†’ dto.setPostIds(...)
  • DTO doesnโ€™t have it โ†’ โŒ compile error

โœ… What v1.1.0 Fixes

โœ” ID is always present

  • Included in DTO
  • No @NotNull
  • Marked as NOT_REQUIRED
  • Server-controlled

โœ” Safe toDto() mapping

dto.setId(entity.getId());
Enter fullscreen mode Exit fullscreen mode

First line. Always.


โœ” Collections โ†’ null (intentional)

dto.setPostIds(null);
Enter fullscreen mode Exit fullscreen mode

Why?

  • null = not loaded
  • emptyList() = loaded but empty โŒ misleading

Also avoids LazyInitializationException entirely.


โœ” Single relationships โ†’ ID only

dto.setUserId(entity.getUser().getId());
Enter fullscreen mode Exit fullscreen mode

No nested objects.
No recursion.
Frontend-friendly.


โœ” Import system fixed

No more garbage like:

com.app.entity.entity.User
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  Design Philosophy

Most generators try to map everything.

Thatโ€™s the root problem.

This update follows a stricter rule:

  • Donโ€™t trigger database access in mappers
  • Donโ€™t assume relationships are loaded
  • Donโ€™t generate code that only works in demos

๐ŸŽฏ Result

You get:

  • Predictable API responses
  • No lazy loading crashes
  • DTOs that always match mappers
  • Code that actually survives real projects

๐Ÿ™Œ Final Thought

This isnโ€™t a flashy release.

Itโ€™s a correctness upgrade.

The kind that saves hours of debugging later.


If youโ€™re already using the plugin โ€” update it.

If not โ€” now itโ€™s finally safe to use in real-world projects.

Would love feedback ๐Ÿ‘‡

Top comments (0)