๐ 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()...
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" }
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());
First line. Always.
โ Collections โ null (intentional)
dto.setPostIds(null);
Why?
-
null= not loaded -
emptyList()= loaded but empty โ misleading
Also avoids LazyInitializationException entirely.
โ Single relationships โ ID only
dto.setUserId(entity.getUser().getId());
No nested objects.
No recursion.
Frontend-friendly.
โ Import system fixed
No more garbage like:
com.app.entity.entity.User
๐ง 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)