Skip to content

EntityUtil.java code snippet

I usually do ‘select’ query before ‘update’ or ‘insert’ query using Jpa, Java.

For example, I must create new entity if the entity is null by ‘select’ query, or I do just setAge(); if the entity exists.

So I code as below by most commonly.

I don’t want to do it, checking null, always. It is very pesky pattern.

So I create a utility class as below.

 


Also published on Medium.

Leave a Reply

Your email address will not be published. Required fields are marked *