Tag: spring data jpa

AspectJ:忽略自定义* .aj文件

为什么aspectj-maven-plugin会忽略我的AnnotationInheritor.aj文件? 我配置错了吗? 我想用自定义注释建议ItemRepository#getById : @Repository public interface ItemRepository extends JpaRepository { // AOP does not work, since autogenerated ItemRepositoryImpl#getById // won’t have @MyAnnotation annotation @MyAnnotation public Item getById(Long id); } @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface MyAnnotation { } @Aspect @Component public class MyAspects { @Around(“@annotation(MyAnnotation)”) public Object execute(ProceedingJoinPoint joinPoint) { // This advice works correct […]

如何使用Spring Data JPA + Neo4j正确设置跨存储持久性?

我正在尝试运行一个非常小的JPA + SDN(Spring Data Neo4j)交叉商店项目,并且我试图certificate使用JPA存储库调用保存部分实体将在Neo4j中创建相应的节点。 我已经按照我在SO,Google和Spring的网站上找到的说明/建议进行了操作,但目前我仍然无法正常工作。 我目前有一个最小的测试项目: https://github.com/simon-lam/sdn-cross-store-poc 该项目使用Spring Boot,并且有一个包含图形实体GraphNodeEntity.java和部分实体PartialEntity.java的简单域。 我编写了一个非常基本的测试PartialEntityRepositoryTest.java来对部分实体进行保存并看到: 似乎使用了错误的事务管理器,因为CrossStoreNeo4jConfiguration类没有正确地自动assemblyentityManagerFactory ,它是null 由于上述^,没有为我的实体分配ID 我根本没有在日志中看到任何SDN活动 我做错了什么吗? 更一般地说,我希望确认一些假设并更好地理解跨存储持久性支持: 要启用它,我是否需要启用高级映射? 作为启用高级映射的一部分,我需要设置AspectJ; 这包括启用加载时间编织? 如果是这样,通过使用@EnableLoadTimeWeaving配置完成? 假设我的所有配置最终都已修复,当我使用JPA存储库保留它们时,我是否应该看到Neo4j中存在部分节点? 这应该由方面驱动的跨店支持来处理吗? 感谢您提供的任何帮助!

如何在hibernate / jpa实体中使用“size”作为字段名?

我有两个JPA实体: VirtualLot和VirtualFiles 。 VirtualFiles扩展了VirtualInode 。 VirtualLot和VirtualFiles之间存在ManyToMany关系,描述为“VirtualLot可以包含VirtualFiles”和“VirtualFile可以与多个VirtualLots关联”实体定义如下: VirtualFile.java @Entity @Table(name = “FIL_FILE”) public class VirtualFile extends VirtualInode { //[…] } VirtualInode.java @Entity @Table(name = “INO_INODE”) @Inheritance(strategy = InheritanceType.JOINED) public class VirtualInode implements Serializable { private Long id; /* The PK */ private long size = 0L; /* The size */ // […] /** * Default constructor […]

编码密码看起来不像BCrypt

我正在使用Spring启动,Spring安全性,oauth2和jwt来validation我的应用程序,但我不断得到这个令人讨厌的错误,我没有想到有什么问题。 希望有人可以帮助我。 我的CustomDetailsS​​ervice类: @Service public class CustomDetailsService implements UserDetailsService { private static final Logger logger = LoggerFactory.getLogger(CustomDetailsService.class); @Autowired private UserBO userBo; @Autowired private RoleBO roleBo; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AppUsers appUsers = null; try { appUsers = this.userBo.loadUserByUsername(username); System.out.println(“========|||=========== “+appUsers.getUsername()); }catch(IndexOutOfBoundsException e){ throw new UsernameNotFoundException(“Wrong username”); }catch(DataAccessException e){ e.printStackTrace(); throw new […]

Spring @Autowired无法连接Jpa存储库

我明显遗漏了一些东西。 我正在制作一个简单的spring boot应用程序,其中包含spring data jpa并面临以下错误: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [locassa.domain.repository.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] … 32 common frames omitted 我的代码: 应用: @SpringBootApplication @ComponentScan(basePackages = […]

Hibernate PersistentSet remove()操作不起作用

我在我的父实体中有一个Set,如下所示: Class Parent { @OneToMany(mappedBy = parent, cascade = CasacadeType.ALL) Set children; } Class Child { @Column(nullable=false) @ManyToOne Parent parent; } 现在事件,如果我对其中一个元素的Set执行remove()操作,它实际上不会被删除。

NoSuchBeanDefinitionException:未定义名为“entityManagerFactory”的bean

我有简单的Spring 4 WebMVC应用程序(Java-config),我想添加JPA。 但是当我尝试运行app(在Tomcat上进行部署)时,我得到:可能是错误的来源是什么? 创建名为’indexController’的bean时出错:注入自动连接的依赖项失败; 嵌套exception是org.springframework.beans.factory.BeanCreationException:无法自动assembly字段:org.demo.webtemplate.db.repository.CustSysRepository org.demo.webtemplate.controllers.IndexController.repository; 嵌套exception是org.springframework.beans.factory.BeanCreationException:创建名为’custSysRepository’的bean时出错:设置bean时无法创建[org.springframework.orm.jpa.SharedEntityManagerCreator]类型的内部bean’(内部bean)#f4da8a0′ property’entalManager’; 嵌套exception是org.springframework.beans.factory.BeanCreationException:创建名为’(内部bean)#f4da8a0’的bean时出错:在设置构造函数参数时无法解析对bean’entalManagerFactory’的引用; 嵌套exception是org.springframework.beans.factory。 NoSuchBeanDefinitionException:未定义名为“entityManagerFactory”的bean 初始化: package org.demo.webtemplate; … public class SpringWebMvcInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(Config.class); ctx.setServletContext(servletContext); Dynamic servlet = servletContext.addServlet(“dispatcher”, new DispatcherServlet(ctx)); servlet.addMapping(“/”); servlet.setLoadOnStartup(1); } } 配置: package org.demo.webtemplate; … @Configuration @EnableWebMvc @ComponentScan(“pl.bzwbk.webtemplate”) @EnableJpaRepositories(“pl.bzwbk.webtemplate.db.repository”) […]

使用Spring Data JPA自动转换参数

在我们的实体bean中,我们使用自定义ID格式,其中包含校验和以validationID实际上是否有效。 Ids看起来像ID827391738979 。 为了确保所有代码只使用正确的ID,我们在ID String周围创建了一个代码包装器: class ID { public ID(String id) { // parse and verify ID } public String toString() { return id; } } 所有代码都使用此ID对象。 但是在我们的实体中,我们将ID定义为String : class SomeEntity { @Column private String itsID; } 现在我们想使用Spring-Data-JPA通过它的id查询一些对象。 所以我们这样做: public SomeEntity findByItsID(ID itsId); 问题是,现在Spring Data JPA尝试将ID类型参数分配给查询,而查询当然需要一个String 。 是否可以让Spring Data JPA在将参数插入查询之前将参数转换为期望的类型(例如通过注册Spring转换器)? 或者,我们是否必须让方法采用这样的字符串: public SomeEntity findByItsId(String itsId); […]

Spring Data(JPA)存储库是否是线程安全的? (又名SimpleJpaRepository线程安全)

我正在使用Spring Data(JPA)存储库来处理CRUD样板。 我这样定义我的存储库接口: import org.springframework.data.repository.CrudRepository; public interface FooRepository extends CrudRepository { public Foo findByXAndYAndZ(X x, Y y, Z z); } Spring然后自动神奇地生成我所述接口的实现。 我们得到的是一个代理,但我相信最终我们会得到一个org.springframework.data.jpa.repository.support.SimpleJpaRepository 。 如果底层目标类是线程安全的, 则 JdkDynamicAopProxy是线程安全的。 因此问题是: SimpleJpaRepository线程安全吗?

@Query,Repository出错

由于我的实体有关系,可能在@Query出错? 哪个存储库包含错误。 创建名为“clickRepository”的bean时出错:init方法的调用失败; 嵌套exception是java.lang.IllegalArgumentException:对于方法public abstract java.lang.String com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)的查询,validation失败! 调节器 @Autowired private ClickService service; /* ie information about fullname_client, id_banner sent to server from client */ @RequestMapping(value = “/sentemail”, method = RequestMethod.POST) @ResponseBody public String sentClick(@RequestParam (“fullnameClient”) String fullnameClient,@RequestParam (“idbanners”) long idbanners) { return service.sent(fullnameClient, idbanners); } 知识库 @Query(“SELECT c.fullnameClient FROM Click AS c join c.idBanner Banners […]