java - Calling a Native Query in the same request life cycle as a JPA managed query causes automatic persist -


i'm sure feature, appreciate pointers/help on issue.

i'm using spring (boot) / jpa (hibernate) stack.

if query entity (called homes) using jpa, , increment calendar field

homeinstance.getlisteddate().add(calendar.date, 1), example 

with no intention of saving change database (it's quick intermediary calculations several routines run on list of these entities).

then call nativequery using injected entitymanager bean.

@autowired entitymanager em; ... query nvqry = em.createnativequery(...) nvqry.getresultlist() 

doing automatically persists changes made entity above (which never supposed persisted.

is there way disable feature without losing in-memory changes? manually persist want using repository, , such whole session persistence useless me.

that's related hibernate flushmode. if haven't modified default configuration, set flushmode.auto.

to alter behavior have provide entitymanagerfactory bean.

in configuration pojo can declare this:

@bean     public localcontainerentitymanagerfactorybean entitymanagerfactory(             final datasource datasource,             final jpavendoradapter jpavendoradapter) {         final localcontainerentitymanagerfactorybean factory = new localcontainerentitymanagerfactorybean();         factory.setpersistenceunitname("domainpc");         factory.setdatasource(datasource);         factory.setjpavendoradapter(jpavendoradapter);         factory.setpackagestoscan(getclass().getpackage().getname());         properties jpaproperties = new properties();         //and here flushmode set.         jpaproperties.setproperty("org.hibernate.flushmode", "commit");         factory.setjpaproperties(jpaproperties);          return factory;     } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -