jpa

Stackoverflow error when saving an Object's toString value - Java/Hibernate/Spring

谁说胖子不能爱 提交于 2021-02-16 20:07:17
问题 I have the following sample entities: Institution @Data @Entity @NoArgsConstructor @EntityListeners(InstitutionAuditListener.class) public class Institution extends Auditable<String> { @OneToMany(mappedBy = "institution", cascade = CascadeType.ALL) @JsonManagedReference private List<RegisteredProgram> registeredPrograms; private String name; } RegisteredProgram @Data @NoArgsConstructor @Entity @EntityListeners(RegisteredProgramAuditListener.class) public class RegisteredProgram extends

Create spring repository without entity

限于喜欢 提交于 2021-02-16 15:47:14
问题 I want to use spring data repository interface to execute native queries - I think this way is the simplest because of low complexity. But when extending interface ex. CrudRepository<T, ID> I need to write T - my entity, which is not available. My native queries does not return any concrete entity, so what is the best way to create spring repository without entity? 回答1: CrudRepository or JpaRepository were not designed to work without an <Entity,ID> pair. You are better off creating a custom

JpaRepository won't save data

泄露秘密 提交于 2021-02-16 11:19:13
问题 I use JpaRepository to save data, but the hibernate.show_sql shows "select" and won't save data. Following is my service: @Autowired private UserRepository userRepository; @PostConstruct public void init() { User admin = new User(); admin.setDisplayName("admin"); admin.setEmailAddress("admin@admin"); admin.setPassword("admin___"); admin.setRegisteredAt(new Date()); admin.setLastAccessAt(new Date()); admin.setUuid(UUID.randomUUID().toString()); try { System.out.println("before save");

JPA auto flush before any query

放肆的年华 提交于 2021-02-16 08:38:25
问题 From JPA documentation I can see that the AUTO is the default flush mode, flush should happen before any query execution. I have tried this on spring boot jpa and I can see the flush won't happen on queries from different entities , is that expected ? even though different entity may have relation to it ( Department <--> Person here ) The flush should trigger before any query according to this article : https://vladmihalcea.com/how-do-jpa-and-hibernate-define-the-auto-flush-mode/ // this

How to query in jsonb postgresql and convert to predicate JPA

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 14:47:56
问题 i have stuck :) does anyone know how query postgresql in jsonb i have table USER INT id, Varchar name, jsonb categoryId the example data in categoryId field like this = [1,2,3,4,5] I have tried this query which works: select * from user where categoryId @> '2'::jsonb ; but how to query with multiple params like select * from user where categoryId @> '1,3,4'::jsonb and i will implement this to hibernate jpa/jpql-predicate, but i want to know native query first Thankyou so much 回答1: In SQL you

No transactional EntityManager available Error

别来无恙 提交于 2021-02-11 14:30:41
问题 I have a below spring setup. Basically I am trying to configure two transaction managers here. One with hibernate and other with JPA. But somehow when I try to run JPA transaction manager, there I get "javax.persistence.TransactionRequiredException: No transactional EntityManager available" error. Appreciate if somebody finds the problem in below code. data-context.xml file as below <bean id="fundBO" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"

how to call the function that was using mysql keywords as parameters by the criteria query?

纵然是瞬间 提交于 2021-02-11 14:24:00
问题 I am using mysql with jpa specification query. I want to know how can i call the function that was using mysql keywords as parameters. Here is the example: select * from schema3.countries order by convert(name using GBK); The convert method using the using and GBK keywords as paramters. I want to call the convert function by the criteria query. I tried the below but it does not working for me. Expression expression = join.get(Country_.NAME); Expression orderExpression = builder.function(

PageRequest and OrderBy method name Issue

被刻印的时光 ゝ 提交于 2021-02-11 14:14:06
问题 in our Spring application we have a table that contains a lot of "Payment" record. Now we need a query that pages the results sorted from the one with the largest total to the smallest, we are facing an error because sometimes the same record is contained in two successive pages. We are creating a PageRequest passed to the repository. Here our implementation: Repository: public interface StagingPaymentEntityRepository extends JpaRepository<StagingPaymentEntity, Long> { Page

Spring boot JPA many to many with extra column insert and update issue

大城市里の小女人 提交于 2021-02-11 13:00:30
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

Spring boot JPA many to many with extra column insert and update issue

耗尽温柔 提交于 2021-02-11 13:00:29
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters