hibernate

Springboot custom Select Query returns No converter found capable of converting from type

我只是一个虾纸丫 提交于 2021-01-28 06:54:14
问题 I am trying to execute a custom select query in Springboot JPA, public interface idnOauth2AccessTokenRepository extends JpaRepository<idnOauth2AccessToken, String>, JpaSpecificationExecutor<idnOauth2AccessToken> { @Query(value = "select IOCA.userName, IOCA.appName, IOAT.refreshToken, IOAT.timeCreated, IOAT.tokenScopeHash, IOAT.tokenState, IOAT.validityPeriod from idnOauth2AccessToken IOAT inner join idnOauthConsumerApps IOCA on IOCA.ID = IOAT.consumerKeyID where IOAT.tokenState='ACTIVE'")

Java Catch and Display SqlExceptionHelper

二次信任 提交于 2021-01-28 06:45:00
问题 Using Hibernate JPA to execute native queries in Oracle DB due to their complexity, I want to catch an exception like " ORA-01722: Nombre non valide " thrown from SqlExceptionHelper class, but what was catching is: class javax.persistence.PersistenceException: could not extract ResultSet The logger error trace me that but not catched : jdbc.spi.SqlExceptionHelper : ORA-01722: Nombre non valide BigDecimal customerId = null; try { Query q = entityManager.createNativeQuery( "select acc.account

How to perform a join fetch in JPA Criteria without unchecked casting?

邮差的信 提交于 2021-01-28 06:30:15
问题 I need to do a JOIN FETCH in JPA Criteria using a static metamodel, however I'm at a loss on how to do it without getting an unchecked exception warning. Suppose we have a Thing entity with a lazily-initialized Other entity inside it. I want to retrieve Things with fetched Others, where other.someField="someValue". This is roughly how I would do it: public List<Thing> getThings() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Thing> cq = cb.createQuery(Thing.class); Root root =

@AdditionalCriteria on a variable rather than a class in EclipseLink

非 Y 不嫁゛ 提交于 2021-01-28 06:25:08
问题 Just like in hibernate, in EclipseLink we have the annotation @AdditionalCriteria that allow us to add a filter on our data. In hibernate it as @Filter and you can either add it on top a a class or on a field like this. @Filter(name="test", condition=":deleted is null") public class MyClass { ... } or @Filter(name="test", condition=":deleted is null") private List<MyClass> list; In EclipseLink the @AdditionalCriteria only works for the first on, on a class. Is there any other annotation that

spring hibernate optimistic locking issue

淺唱寂寞╮ 提交于 2021-01-28 06:14:55
问题 This is my Repository layer: class RepositoryImpl implements Repository{ @Override public Serializable saveOrUpdate(Object obj) { return getSession().save(obj); } @Override public Object get(Class refClass, Serializable key) { return getSession().get(refClass, key); } } This is my Service layer: class ServiceImpl implements Service{ @Autowired Repository repository; @Override @Transactional public Object findUserById(Serializable key) { // TODO Auto-generated method stub return repository.get

Spring Using SpEL Principal

好久不见. 提交于 2021-01-28 06:02:24
问题 I'm trying to use SpEL has in this document https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions to do a query filtering results by the ?#{principal.id} The problem is that Spring returns an exception org.hibernate.QueryException: Not all named parameters have been set: [1] [select p , p.store, p.category from Product p JOIN p.store s JOIN p.category c WHERE p.store.id = :id AND p.keywords LIKE :keyword AND p.store.ownerId = ?1 ]; nested exception is java.lang

Problem with @OneToMany relations in a Generic CRUD

北战南征 提交于 2021-01-28 05:54:54
问题 I have this generic CRUD (Controller, Repository, Service, Specification) with multiple entities that use @OneToMany annotations. The project only starts when I comment on these annotations, otherwise I get an error that always indicates a different "DAO" file. Struchture: oga-servicio-principal -src/main/java --com.oga.springboot ---app.principal ----controllers ----crud (My Generic CRUD files) -----controllers -----models ------dao ------dto ------entity ------service ------specifications -

JPA @OnetoOne self reference relationship with both columns non null

耗尽温柔 提交于 2021-01-28 05:28:16
问题 I have an existing database table For e.g. T_STUDENTS on top of which I have to create a JPA entity. All three columns in the table are NON NULL and the table has a self-reference as mentor_id id | name | mentor_id -----|---------|---------- 1 | John | 1 -----|---------|---------- 2 | Marc | 1 -----|---------|---------- 3 | Abby | 2 -----|---------|---------- 4 | Jimy | 3 -----|---------|---------- 5 | Boni | 4 -----|---------|---------- Each student has a mentor who is also a student. There

How to make both bidirectional hiberbate entities serialized

两盒软妹~` 提交于 2021-01-28 05:20:18
问题 I have 2 Entities: public class Restaurant { @OneToMany(fetch = FetchType.LAZY, mappedBy = "restaurant") private Set<Vote> votes; } and public class Vote { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "restaurant_id", nullable = false) private Restaurant restaurant; } if I try to get both of them like that @Query("SELECT r FROM Restaurant r JOIN FETCH r.vote ") I get Infinite Recursion with Jackson JSON. So I managed to find a way to handle that: public class Restaurant {

why saveAll() always inserts data instead of update it?

狂风中的少年 提交于 2021-01-28 04:51:51
问题 Spring Boot 2.4.0 , DB is MySql 8 . Data is fetched every 15 seconds from remote with REST and storing it to MySql DB with saveAll() . Which call the save() method for all the given entities. All data has set ID. And I am expecting that if there is no such id at DB - it will be inserted . If such ID is already presented at DB - it will be updated . Here is snipped from the console: Hibernate: insert into iot_entity (controller_ref, description, device_id, device_ref, entity_type_ref, hw