Skip to content
Advertisement

What is the best way to update data in database using Native Query

Here if one of data in rule object is null apart from rule_id(As it’s necessary) this query will fail, so instead I can format string for each value in Rule object and concat them excluding which has null value in Rule object but is there any better way to do this? Because if there are 100s of columns then this will not be ideal process. So does JPA has anything which can fulfill my requirement.

Advertisement

Answer

The JPA way of doing it is to create entity mappings:

A spring jpa repository:

And a service to handle persistance:

And use it like:

The JPA provider will generate the query for you behind the curtains, no need for complicated native queries.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement