jpa

JPA 2.0 disable session cache for unit tests

為{幸葍}努か 提交于 2020-12-10 06:45:36
问题 I am writing unit test for my services e. g. : @Test @Rollback(value = true) public void testMethod() { // insert test data myService.Method(); // read/write from DB // asserts go here } While application running, a new transaction is created every time method A entered. But during the unit test execution - when test testMethod entered. So method A doesn't create new one. For proper testing I need to clear cache before every call to service inside test.I don't want to write Session.clear()

Same query method and parameters with different return in Spring Data

你。 提交于 2020-12-06 06:37:52
问题 I want to use projections in order to return less elements for the same queries. Page<Network> findByIdIn(List<Long> ids); Page<NetworkSimple> findByIdIn(List<Long> ids); Since the queries are created using the name of the method, what options do I have to do the same query but with different name ? 回答1: Spring Data query via method is constructed by convention and you can't change the name and yet expecting a same behavior. You can try to use @Query annotations which doesn't depend on the

Same query method and parameters with different return in Spring Data

五迷三道 提交于 2020-12-06 06:34:26
问题 I want to use projections in order to return less elements for the same queries. Page<Network> findByIdIn(List<Long> ids); Page<NetworkSimple> findByIdIn(List<Long> ids); Since the queries are created using the name of the method, what options do I have to do the same query but with different name ? 回答1: Spring Data query via method is constructed by convention and you can't change the name and yet expecting a same behavior. You can try to use @Query annotations which doesn't depend on the

JPA subquery in from clause

别说谁变了你拦得住时间么 提交于 2020-12-05 17:32:10
问题 We're developing a web application which uses EJB to connect to a database. In our DB model, we have a mobile devices table, another one with features, and the last one that maps the values of the features with the phone models. models (id_model,...) features (id_feature, ...) model_features (id_model, id_feature, value) We want to perform a query that gets the models ordered by the number of matching features. It's to say, we pass a list of features to match (i.e. from 1 to 9), and we want

JPA Query Returning Same Result for different Parameter

偶尔善良 提交于 2020-12-05 11:58:29
问题 I'm running into an issue where my query method is in a foreach loop, and each time I'm passing in a different parameter to retrieve different information. However, after the FIRST iteration of the loop, the query data gets cached (I think) and returns the same data for subsequent loops. Here is my code: @Transactional(readOnly = true) public List<InitiativeReport> getInitiativeReports() throws Exception { try { List<InitiativeReport> ir = new ArrayList<InitiativeReport>(); List<Initiative>

how to map between two tables with @EmbeddedId s?

喜欢而已 提交于 2020-12-05 11:54:26
问题 So what I have here is a diagram that looks like this, which can be found in this Answer Here. +---------------+ +-------------------+ | PRODUCTS |-----< PRODUCT_VARIANTS | +---------------+ +-------------------+ | #product_id | | #product_id | | product_name | | #variant_id | +---------------+ | sku_id | | +-------------------+ | | +--------^--------+ +--------^--------+ | PRODUCT_OPTIONS |-----< VARIANT_VALUES | +-----------------+ +-----------------+ | #product_id | | #product_id | |

how to map between two tables with @EmbeddedId s?

半城伤御伤魂 提交于 2020-12-05 11:53:51
问题 So what I have here is a diagram that looks like this, which can be found in this Answer Here. +---------------+ +-------------------+ | PRODUCTS |-----< PRODUCT_VARIANTS | +---------------+ +-------------------+ | #product_id | | #product_id | | product_name | | #variant_id | +---------------+ | sku_id | | +-------------------+ | | +--------^--------+ +--------^--------+ | PRODUCT_OPTIONS |-----< VARIANT_VALUES | +-----------------+ +-----------------+ | #product_id | | #product_id | |

how to do a JOIN FETCH in jpa criteria

冷暖自知 提交于 2020-12-05 10:30:06
问题 I am trying to translate the query below to criteria api. SELECT er from ereturn er JOIN FETCH product_item pi ON pi.ereturn_id = er.id WHERE pi.status = "RECEIVED" To something like this: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Ereturn> criteria = builder.createQuery( Ereturn.class ); Root<Ereturn> er = criteria.from(Ereturn.class); Join<Ereturn, ProductItem> productItemJoin = er.join("productItems", JoinType.LEFT); Fetch<Ereturn, ProductItem> productItemFetch = er

how to do a JOIN FETCH in jpa criteria

混江龙づ霸主 提交于 2020-12-05 10:29:49
问题 I am trying to translate the query below to criteria api. SELECT er from ereturn er JOIN FETCH product_item pi ON pi.ereturn_id = er.id WHERE pi.status = "RECEIVED" To something like this: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Ereturn> criteria = builder.createQuery( Ereturn.class ); Root<Ereturn> er = criteria.from(Ereturn.class); Join<Ereturn, ProductItem> productItemJoin = er.join("productItems", JoinType.LEFT); Fetch<Ereturn, ProductItem> productItemFetch = er

Is there are way to scroll results with JPA/hibernate?

﹥>﹥吖頭↗ 提交于 2020-12-01 06:43:40
问题 I found some hint in Toplink Query query = em.createQuery("SELECT e FROM Employee e ORDER BY e.lastName ASC, e.firstName ASC"); query.setHint("eclipselink.cursor.scrollable", true); ScrollableCursor scrollableCursor = (ScrollableCursor)query.getSingleResult(); List<Employee> emps = scrollableCursor.next(10); is there are jpa/hibernate alternative? 回答1: To my knowledge, there is nothing standard in JPA for that. With Hibernate, the closest alternative I'm aware of would be the Query /