相关疑难解决方法(0)

Spring数据jpa中save和saveAndFlush的区别

我试图通过测试一些CRUD操作来学习弹簧数据JPA JpaRepository.

我碰到两个方法savesaveAndFlush.我没有区分这两者.在调用时save我的更改也被保存到数据库中,因此有什么用处saveAndFlush.

java spring hibernate jpa spring-data-jpa

119
推荐指数
3
解决办法
12万
查看次数

查询指定的连接提取,但提取的关联的所有者不在选择列表中

我正在选择两个id列但指定了错误:

org.hibernate.QueryException: **query specified join fetching, but the owner of the fetched association was not present in the select list** 

[FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=r,role=null,tableName=REVISIONS,tableAlias=revision1_,origin=ENTITY_CHANGED_IN_REVISION entitychan0_,columns={entitychan0_.REV_ID ,className=ru.csbi.registry.domain.envers.Revision}}] [ select ec.id as entityChangeId, r.id as revisionId from ru.csbi.registry.domain.envers.EntityChange as ec  inner join fetch ec.revision as r  where ec.groupEntityId = :groupEntityId and ec.groupName = :groupName  and r.timestamp < :entityDateFrom  and r.timestamp > :entityDateTo  and (        ec.revisionType in (0, 5, 1, 4, 2 )       and not ( ec.otherGroupEntityModified = false and …
Run Code Online (Sandbox Code Playgroud)

hibernate join fetch

67
推荐指数
3
解决办法
7万
查看次数

如何避免警告"使用集合提取指定的firstResult/maxResults;在内存中应用!" 什么时候使用Hibernate?

我在服务器日志中收到警告"使用集合提取指定的firstResult/maxResults;在内存中应用!" .然而一切正常.但我不想要这个警告.

我的代码是

public employee find(int id) {
    return (employee) getEntityManager().createQuery(QUERY).setParameter("id", id).getSingleResult();
}
Run Code Online (Sandbox Code Playgroud)

我的疑问是

QUERY = "from employee as emp left join fetch emp.salary left join fetch emp.department where emp.id = :id"
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa jpql ejb-3.0

27
推荐指数
4
解决办法
3万
查看次数

JPQL Join Fetch在Spring Data中的ManyToOne关联中不起作用

我试图在Spring Data中使用JPQL优化基本查询,以避免对数据库进行多次查询,并使用JOIN Fetch检索一个查询中的所有信息,并且我不断收到此异常:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=Business.Countries,tableAlias=country1_,origin=BUSINESS.COAPPLICANTS coapplican0_,columns={coapplican0_.Country_Id ,className=com.medifast.entity.core.Country}}] [select count(ca) from com.medifast.entity.core.CoApplicant ca LEFT JOIN FETCH ca.country LEFT JOIN FETCH ca.state where ca.client.id = :clientId]; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=Business.Countries,tableAlias=country1_,origin=BUSINESS.COAPPLICANTS coapplican0_,columns={coapplican0_.Country_Id …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa spring-data-jpa

11
推荐指数
1
解决办法
5598
查看次数

具有规范、分页和标准的 Spring Data JPA 存储库

我正在为实体列表实现搜索/过滤服务,使用具有规范和分页功能的 Spring Data JPA 存储库。我正在尝试减少查询次数(n+1 问题)并使用标准获取机制获取嵌套数据。

我有两个实体类:

@Entity
@Table(name = "delegations")
public class Delegation {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    @ManyToOne
    private Customer customer;

    // more fields, getters, setters, business logic...

}
Run Code Online (Sandbox Code Playgroud)

@Entity
@Table(name = "customers")
public class Customer {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    // more fields, getters, setters, business logic...
}
Run Code Online (Sandbox Code Playgroud)

DTO过滤器类:

public class DelegationFilter {

    private String customerName;

    // more filters, getters, setters...
}
Run Code Online (Sandbox Code Playgroud)

和搜索/过滤服务:

public class DelegationService {
    public Page<Delegation> findAll(DelegationFilter …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-data spring-data-jpa

7
推荐指数
1
解决办法
6372
查看次数

Spring Data JPA:如何不在countQueries中重复自己?

我正在使用Spring Data JPA存储库(1.7.2),通常遇到以下情况:

  • 实体具有延迟加载的集合
  • 有时会急切地获取这些集合(通过JPAQL fetch join
  • 存储库通常返回Page<Foo>而不是List<Foo>

我需要提供countQuery@Query在返回的存储库中使用提取联接的每个对象Page。此问题已在此StackOverflow问题中进行了讨论

我典型的存储库方法如下所示:

@Query(value = "SELECT e FROM Employee e LEFT JOIN FETCH e.addresses a " +
    "WHERE e.company.id = :companyId " +
    "AND e.deleted = false " +
    "AND e.primaryAddress.deleted = false " +
    "ORDER BY e.id, a.id",
    countQuery="SELECT count(e) FROM Employee e WHERE e.companyId = :companyId AND e.deleted = false AND e.primaryAddress.deleted = false"
)
Page<Employee> findAllEmployeesWithAddressesForCompany(@Param("companyId") long …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-data

6
推荐指数
1
解决办法
2987
查看次数

标签 统计

hibernate ×5

java ×4

jpa ×4

spring ×3

spring-data-jpa ×3

spring-data ×2

ejb-3.0 ×1

fetch ×1

join ×1

jpql ×1