I am using Netbeans 12.0, and to create my Entity classes for my DB tables, I use Netbeans Entity Classes from Database
. It works great other than the fact it defaults all my date
columns to the pre Java 8 Date
classes, and I recently discovered removing the @Temporal
annotation from my class variables (correspond with columns in my tables) with LocalDate
does not cause issues.
This is what Netbeans creates:
@Column(name = "delivery_date")
@Temporal(TemporalType.DATE)
private Date deliveryDate;
Here is my updated version that works:
@Column(name = "delivery_date")
private LocalDate deliveryDate;
Is it possible to make Netbeans use the LocalDate
class when creating my entity classes from my database?
I have many tables which have corresponding entities in my Java app, while it is theoretically feasible for me to go through each one and replace the columns with dates, it does not sound like fun especially for future entities.
My project is Java 8, using JPA 2.2 and EclipseLink 2.7.7.
I'm afraid that's not possible, when using regular Netbeans version.
Here is snippet from class JavaPersistenceGenerator responsible for that mapping:
As you can see
java.util.Date
is hard-coded there and cannot be configured.You can checkout Netbeans sources from GitHub, change
java.util.Date
tojava.time.LocalDate
in class:Rebuild Netbeans sources and replace file:
With corrected version from:
That will lead to the desired result.