hibernate

JPA inheritance @EntityGraph include optional associations of subclasses

六月ゝ 毕业季﹏ 提交于 2020-08-24 05:12:10
问题 Given the following domain model, I want to load all Answer s including their Value s and their respective sub-children and put it in an AnswerDTO to then convert to JSON. I have a working solution but it suffers from the N+1 problem that I want to get rid of by using an ad-hoc @EntityGraph . All associations are configured LAZY . @Query("SELECT a FROM Answer a") @EntityGraph(attributePaths = {"value"}) public List<Answer> findAll(); Using an ad-hoc @EntityGraph on the Repository method I can

TransactionRequiredException: no transaction is in progress while using JPAItemWriter

∥☆過路亽.° 提交于 2020-08-22 12:03:53
问题 I am facing weird issue with an application which is a spring boot application. Details Here: The app has a spring batch job which uses JpaItemWriter for performing the writes to the database. Also, the application is configured to use hibernate ItemWriter configuration as follows: @Bean(name = "itemWriter") @StepScope public ItemWriter<Record> itemWriter() { JpaItemWriter<Record> itemWriter = new JpaItemWriter<>(); itemWriter.setEntityManagerFactory(emf); return itemWriter; } The batch job

Spring boot Jpa: hibernate as default?

北慕城南 提交于 2020-08-22 10:51:32
问题 if one uses the spring-boot-starter-data-jpa dependency and extends repository classes by org.springframework.data.jpa.repository.JpaRepository , is this 'plain jpa' or hibernate? What is the difference? 回答1: JPA is an interface and Hibernate is the implementation. By default Spring uses Hibernate as the default JPA vendor. If you prefer, you can use any other reference implementation e.g. EclipseLink for the Java Persistence in your Spring project. 回答2: From the docs: Spring Data JPA aims to

Hibernate : Why FetchType.LAZY-annotated collection property eagerly loading?

我与影子孤独终老i 提交于 2020-08-22 09:23:06
问题 I tried to implement simple one-to-many association. after inspecting the item object with debugging mode, I found that List<Bid> bids already loaded. But List<Bid> bids property is annotated with FetchType.LAZY. some books and web pages claim that FetchType.LAZY is a hint JPA providers accept or reject. But I wonder on what condition JPA providers ignore FetchType.LAZY. Thank you in advance. @Entity @Table(name = "ITEM") public class Item implements Serializable { @Id private Long id = null;

JPA AttributeConverter not honored in a Spring-data/hibernate query when used in a composite key

这一生的挚爱 提交于 2020-08-22 05:30:52
问题 This is my enum: public enum FooBarType { Foo, Bar; @javax.persistence.Converter public static class Converter implements AttributeConverter<FooBarType, String> { @Override public String convertToDatabaseColumn(FooBarType t) { return t.toString(); } @Override public FooBarType convertToEntityAttribute(String s) { for (FooBarType value : FooBarType.values()) { if (value.name().equalsIgnoreCase(s)) { return value; } } throw new IllegalArgumentException("Invalid value for enum: " + s); } } }

Are persistence annotations in domain objects a bad practice?

被刻印的时光 ゝ 提交于 2020-08-21 01:59:40
问题 I realize that persistence frameworks such as Morphia and Hibernate rely on annotations on domain objects to do their magic. At some level, it seems to me that this is inserting persistence concerns into the domain layer which is something we're supposed to strive to avoid. Is this something that I should try to dodge by perhaps using an external configuration file or maybe separate DTOs from the domain model? Or is this little leak between the persistence and domain layers generally regarded

Why does my JQL query return a different result than the equivalent CriteriaBuilder query?

☆樱花仙子☆ 提交于 2020-08-20 12:11:54
问题 I'm using Dropwizard Hibernate and am having issues with my tests. I've simplified this example as much as possible. I create a Foo , update it, and then try to fetch it. Using a raw query gets the correct result, but the equivalent CriteriaBuilder query doesn't catch the update. What am I doing wrong? @Test public void testFoo() { String id = "12345"; // Create Foo foo = Foo.builder() .id(id) .name("old-name") .build(); sessionFactory.getCurrentSession().replicate(foo, ReplicationMode

Why does my JQL query return a different result than the equivalent CriteriaBuilder query?

馋奶兔 提交于 2020-08-20 12:09:39
问题 I'm using Dropwizard Hibernate and am having issues with my tests. I've simplified this example as much as possible. I create a Foo , update it, and then try to fetch it. Using a raw query gets the correct result, but the equivalent CriteriaBuilder query doesn't catch the update. What am I doing wrong? @Test public void testFoo() { String id = "12345"; // Create Foo foo = Foo.builder() .id(id) .name("old-name") .build(); sessionFactory.getCurrentSession().replicate(foo, ReplicationMode

Why does my JQL query return a different result than the equivalent CriteriaBuilder query?

不想你离开。 提交于 2020-08-20 12:09:33
问题 I'm using Dropwizard Hibernate and am having issues with my tests. I've simplified this example as much as possible. I create a Foo , update it, and then try to fetch it. Using a raw query gets the correct result, but the equivalent CriteriaBuilder query doesn't catch the update. What am I doing wrong? @Test public void testFoo() { String id = "12345"; // Create Foo foo = Foo.builder() .id(id) .name("old-name") .build(); sessionFactory.getCurrentSession().replicate(foo, ReplicationMode

处理“ java.lang.OutOfMemoryError:PermGen空间”错误

别来无恙 提交于 2020-08-20 07:32:23
问题: Recently I ran into this error in my web application: 最近,我在Web应用程序中遇到此错误: java.lang.OutOfMemoryError: PermGen space java.lang.OutOfMemoryError:PermGen空间 It's a typical Hibernate/JPA + IceFaces/JSF application running on Tomcat 6 and JDK 1.6. 这是在Tomcat 6和JDK 1.6上运行的典型Hibernate / JPA + IceFaces / JSF应用程序。 Apparently this can occur after redeploying an application a few times. 显然,这可能是在重新部署应用程序几次之后发生的。 What causes it and what can be done to avoid it? 是什么原因引起的,可以采取什么措施避免它发生? How do I fix the problem? 我该如何解决该问题? 解决方案: 参考一: https://stackoom.com/question/Mx9/处理-java-lang-OutOfMemoryError-PermGen空间