Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test JPA2 mappings in Java EE project?

I'm working on a Java project where I've been tasked to write a few database mappings against a legacy database.
While doing this, I started to question how I was supposed to test if my mappings were valid or not. Most likely I've done a couple of mistakes in my mappings as I'm not a seasoned JPA annotations user.

So what is the general opinion/best-practice regarding testing manually written JPA mappings though annotations?

like image 725
netbrain Avatar asked Mar 01 '26 20:03

netbrain


1 Answers

If you're using Hibernate, you can set the following in your persistence.xml file:

<property name="hibernate.hbm2ddl.auto" value="validate" />

to get Hibernate to validate the existing schema but NOT make any changes to the schema. It's a quick way to see if your mappings are valid or not against your DB.

like image 170
Tom Tresansky Avatar answered Mar 04 '26 09:03

Tom Tresansky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!