{"id":5670,"date":"2014-04-04T18:47:27","date_gmt":"2014-04-04T18:47:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/04\/problem-about-spring-data-jpa-collection-of-common-programming-errors\/"},"modified":"2014-04-04T18:47:27","modified_gmt":"2014-04-04T18:47:27","slug":"problem-about-spring-data-jpa-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/04\/problem-about-spring-data-jpa-collection-of-common-programming-errors\/","title":{"rendered":"problem about spring-data-jpa-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/mILYM.jpg?s=32&amp;g=1\" \/><br \/>\nSitansu<br \/>\njava spring spring-data-jpa spring-boot<br \/>\nWhy does the addition of @EnableAutoConfiguration to the following spring-boot app cause it to not create an entityManagerFactory? If I remove @EnableAutoConfiguration everything works fine. Can anyone shed light on this behaviour?package test.builder;import javax.sql.DataSource;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; im<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/db83cf641ff371bbd5016456dd164288?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCFL_Jeff<br \/>\njava hibernate inheritance jpa spring-data-jpa<br \/>\nConsider the following hierarchy, where entities WidgetA and WidgetB extend an abstract Widget superclass:@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class Widget implements Serializable {@Column(name=&#8221;serialNumber&#8221;, length=64, nullable=false, unique=true)private String serialNumber;&#8230;and@Entity public class WidgetA extends Widget implements Serializable { &#8230;and@Entity public class WidgetB extends Widget implements Serializable { &#8230;I need to search for Widgets b<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ef3dfb86a6c8249fe0c0de25dd9d9e38?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nLeonard Br\u00fcnings<br \/>\nspring hibernate spring-data-jpa spring-transactions<br \/>\nIn our Tests we see this mysterious StackOverflowError in our logs. Our tests still complete normally, but I&#8217;d still like to fix it if possible. Any ideas what is causing this infinite recursion and how to fix it?13569 [main] DEBUG org.hibernate.SQL &#8211; select sequence_next_hi_value from hibernate_sequences where sequence_name = &#8216;IDS&#8217; for update Hibernate: select sequence_next_hi_value from hibernate_sequences where sequence_name = &#8216;IDS&#8217; for update 13570 [main] DEBUG org.hibernate.SQL &#8211; insert i<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9b8612f4dbb037edc0f5ce82df05adde?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbalteo<br \/>\nspring hibernate jpa spring-data-jpa<br \/>\nI have an issue with a Spring controller method. It actually does two updates on the same entity which causes the StaleObjectStateException. The problem is that when I retrieve the Member instance, I think it somehow causes an update (see \/\/UPDATE ONE) of the Advertisement instances (this is not wanted actually) and when I update the Advertisement instance (see \/\/UPDATE TWO), then it throws a StaleObjectStateException.My question is how can I prevent this exception from occurring in my case (bea<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1aaf9d211e31aaa2faf479ee96e45807?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1555190<br \/>\nspring jpa-2.0 spring-data-jpa<br \/>\nI have query as such :@Query(&#8220;select a from Ability a where a.eventLogic = ?1 AND a.abilitySetId = ?2 ORDER BY RAND() LIMIT ?3&#8221;)BUt i get an error:Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: LIMIT near line 1, column 117How can i programmatically put in the limit number?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cf1b1ffa204cf0dcb173ff527a6cfb53?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMariusz<br \/>\nhibernate jpa spring-data-jpa<br \/>\nI use JPA with hibernate. I want to check that row with specified name and username exists. The following query raises an error:@Query(&#8220;select exists (select 1 from Strategy s where s.name=:name and s.username=:username)&#8221;) Boolean exists2(@Param(&#8220;name&#8221;) String name,@Param(&#8220;username&#8221;) String username);Error:Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [select exists (select s from com.soft.domain.strategy.Strategy s where s.name=:name and s.username=:username)]<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MVk6m.gif?s=32&amp;g=1\" \/><br \/>\ndhroove<br \/>\njava hibernate exception jpa-2.0 spring-data-jpa<br \/>\nI don&#8217;t know if this approach is the best or not. But I have a requirement where I need to handle Spring JPA repository (DAO layer) exception. Handle in the sense may be propogate it to UI or may be do some logic on service layer.Now as per present scenario from over repositories all our SQL Exception got wrapped into Runtime exception DataAccessException.Now one way if I want to propogate this Exceptions to my UI layer than I catch this Runtime Exception on Service layer and wrap this exception<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/92997c3fbc76408f78debe6bc53c5bb3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nchrylis<br \/>\njava spring configuration annotations spring-data-jpa<br \/>\nI&#8217;ve got the spring configuration class:@Configuration @EnableJpaRepositories InfrastructureContextConfiguration@Beanpublic LocalContainerEntityManagerFactoryBean entityManagerFactory() {&#8230;}I wish to set the entityManagerFactoryRef attribute of the @EnableJpaRepositories with entityManagerFactory().getObject() invocation. Can I do that and how if it is allowed?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b8cb5d6d43ed44788472b977cef6f1d7?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMatt Whipple<br \/>\nspring-data-jpa<br \/>\nI&#8217;m presently struggling with getting Spring Data JPA Auditing to work, it is presently not setting the fields and doesn&#8217;t seem to be getting called in any way when working with Entities. In particular any insight into how it hooks into the standard flow of persisting Entities would be helpful.I&#8217;m presently using Spring Data JPA 1.5.0.M1 with Spring 3.2.6 and the basic configuration for the auditing piece is:@Configuration @EnableJpaAuditing(auditorAwareRef = &#8220;auditorAware&#8221;) @EnableJpaRepositor<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9b8612f4dbb037edc0f5ce82df05adde?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbalteo<br \/>\njpa spring-roo spring-data spring-data-jpa<br \/>\nI use Spring Roo + Spring Data + QueryDSL and I have the following classes\/interfaces:public interface FamilyAdvertisementRepositoryCustom { }@RooJpaRepository(domainType = FamilyAdvertisement.class) public interface FamilyAdvertisementRepository extends FamilyAdvertisementRepositoryCustom { }public class FamilyAdvertisementRepositoryImpl extends QueryDslRepositorySupport implements FamilyAdvertisementRepositoryCustom {\/\/NO CONSTRUCTOR }all in following package: com.bignibou.repository;With foll<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c22a041394cad200cb3576bd9d9a5ecd?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nchrisjleu<br \/>\njava spring jpa spring-data-jpa<br \/>\nAnother question for my EclipseLink and Spring (MVC and spring-data) version 3.1.1 set-up:I&#8217;m trying to get JPA working without the use of the persistence.xml file in accordance with this article. In the article it says:Usually, JPA defines a persistence unit through theMETA-INF\/persistence.xml file. Starting with Spring 3.1, this XML fileis no longer necessary &#8211; the LocalContainerEntityManagerFactoryBeannow supports a &#8216;packagesToScan&#8217; property where the packages to scanfor @Entity classes can b<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/67e4696da05b53a01ff31c7d9bbc1581?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nQuantum<br \/>\nspring transactions openjpa spring-data-jpa atomikos<br \/>\nI am using Spring Data JPA (SDJ) and during my integration tests, I&#8217;ve come across a weird situation &#8211; I&#8217;ve probably misconfigured something, but I fail to see what that might be.In a nutshell &#8211; it would seem that SDJ simply fails to invoke an implementation of Spring&#8217;s PlatformTransactionManager once there is any kind of method declared on repository interface (i.e., the one that extends JpaRepository&lt;T, ID&gt;). I&#8217;ve drilled down this behaviour to a pretty banal reason &#8211; in this situation,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0d952ad35ffddbb6b31200889f84b976?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nshelley<br \/>\njava spring spring-data spring-data-jpa<br \/>\nIn a web application that uses Spring Data JPA with Hibernate, we utilize the web pagination functionality to provide paging and sorting capabilities in various lists of entities.@Controller public class MyEntityController {@RequestMapping(method = RequestMethod.GET)public ModelAndView list(Pageable pageable) { &#8230; } }@Configuration public class MyWebMvcConfig extends WebMvcConfigurationSupport {@Overridepublic void addArgumentResolvers(List&lt;HandlerMethodArgumentResolver&gt; argumentResolvers<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aedecbfdd2ac379adc9d6265935686ce?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmasi<br \/>\njava spring annotations spring-data spring-data-jpa<br \/>\ni followed the tutorial posted here to get a basis application to work with Spring Data JPA. Now, how i understood, using the configuration&lt;jpa:repositories base-package=&#8221;my.package.to.scan&#8221; \/&gt;should result in that package beeing scanned by Spring Data JPA for interfaces extending JpaRepository and create a concreate bean of it so it can be used anywhere in my service classes using simple Spring @Autowired. But it fails, saying it can&#8217;t find a bean with className (which is the default name<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9ec7b8536a0d90efdc4136283add93c8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMalave<br \/>\njava groovy jpa-2.0 spring-data spring-data-jpa<br \/>\nI have an Item and this Item could have any number of categories. I need to do a query to return all the items that correspond to a category. First let me put the domain objects:@Entity class Item {@Id@GeneratedValueLong id;String name@ElementCollection@JoinColumn(name = &#8220;security_id&#8221;)List&lt;Category&gt; categories = [] }And here is the enum with the categoriespublic enum Category {OFFICE(&#8220;office&#8221;),HOME(&#8220;home&#8221;),GARDEN(&#8220;garden&#8221;)final String value;private Category(String value) {this.value = valu<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a648ccb47bbbe9497c073315aac4d33e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJoachim Sauer<br \/>\nsolr spring-data spring-data-jpa spring-data-solr<br \/>\nTo enable full text search, I ever used hibernate-search and solrJ, No I am trying spring-data-solr, but found I seems not working together with spring-data-jpa. I just can&#8217;t make the configuration correct. If I add the following solr configuration xml to my project.I get error message. The config xml file of spring-data-solr is:&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt; &lt;beans xmlns=&#8221;http:\/\/www.springframework.org\/schema\/beans&#8221; xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221; xmlns:p<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sitansu java spring spring-data-jpa spring-boot Why does the addition of @EnableAutoConfiguration to the following spring-boot app cause it to not create an entityManagerFactory? If I remove @EnableAutoConfiguration everything works fine. Can anyone shed light on this behaviour?package test.builder;import javax.sql.DataSource;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; im CFL_Jeff java hibernate inheritance jpa spring-data-jpa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5670","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5670"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5670\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}