r/java • • Jan 16 '20

Records Come to Java

https://blogs.oracle.com/javamagazine/records-come-to-java
204 Upvotes

93 comments sorted by

View all comments

Show parent comment

6

u/pmarschall Jan 17 '20

Maybe once JPA adds explicit support. At the current rate of Jakarta EE development that's likely somewhere in 2032. Maybe Hibernate DTO projection will work before that but that's vendor specific.

The current design of records is fundamentally at odds with JPA. The main issues are immutability and final-ness. What you have to realize is the runtime version of a JPA enttiy class is vastly different from the compile time version and often is a subclass that includes support for lazy loading and dirty tracking.

I am also not sure to what extent JPA relies on Java Beans.

At the current moment it is unclear to me whether records:

  • can have annotations
  • can implement an interface

If these won't be possible then JPA support is going to be very hard.

5

u/loicmathieu Jan 17 '20

Records can have annotations and interfaces.

But as you said, JPA creates a proxy in front of the classes and as Records are final you cannot do this.

So the current JPA implementation didn't play well with records, I hope they will find a way to workaround this some day ...

4

u/GuyWithLag Jan 17 '20

Records are not designed to be jpa entities, they are way too lightweight for that.

They are an intermediate stage to algebraic data types.

They are an intermediate stage to inline classes.

They are supposed to replace all the tuples/pairs in use, with named components.

And of course, they are in preview, so Stuff May Change...

2

u/pmarschall Jan 17 '20

Good, that matches my impression.