标签: spring-data

如何在Spring Data MongoDB存储库中查询日期?

我的域名对象 -

Person{
    String name;
    Date born;
}
Run Code Online (Sandbox Code Playgroud)

我有一个PersonRepository

PersonRepository{
    @Query(value="{'born': {$gt: new Date(?0)} }")
    findPerson(Date bornAfter);
}
Run Code Online (Sandbox Code Playgroud)

我想抓住在某个约会后出生的所有人.但这不起作用.我错过了什么?mongodb控制台中"born"的日期格式如下

ISODate("2011-11-16T09:46:33.750Z")
Run Code Online (Sandbox Code Playgroud)

我试图在data-jpa源代码中寻找一个单元/集成测试.找不到任何东西.有人能指点我吗?

java spring mongodb spring-data spring-data-mongodb

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

Spring Data动态查询

我正在尝试使用spring数据设置动态查询,基本上我有一堆具有一系列特征的数组,我需要根据这些特性组装查询,几乎就像"WHERE特征= A AND特征= B AND特征= C"但特征量可能不同.

我注意到我可以使用@Query注释但是可以将@Query的结果分页吗?

有没有其他方法可以实现这一目标?

Page<Recipe> findDistinctByNameContainingAndOrganizationAndCharacteristicsInOrIngredientsContainingAndOrganizationAndCharacteristicsInOrDescriptionContainingAndOrganizationAndCharacteristicsInAllIgnoreCase(
        String name, Organization organization1, List<Characteristic> characteristic1,
        String ingredients, Organization organization2, List<Characteristic> characteristic2,
        String description, Organization organization3, List<Characteristic> characteristic3,
        Pageable pageable);
Run Code Online (Sandbox Code Playgroud)

java spring dynamicquery spring-data

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

如何查看Spring Data MongoDB生成的存储库实现?

Spring Data生成的存储库实现是什么时候?在编译时还是运行时?我可以看到Spring Data生成的实现存储库实现吗?

repository mongodb spring-data spring-data-mongodb

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

为什么没有使用Spring Data JPA设置版本属性?

想知道@VersionSpring Data REST中的注释如何用于ETag,我没有看到由于某种原因填充了ETag

@Entity
@EntityListeners(AuditingEntityListener.class)
public class Venue implements Serializable {

  private static final long serialVersionUID = -5516160437873476233L;

  private Long id;

  ...
  // other properties

  private Long version;

  private Date lastModifiedDate;

  // getters & setters

  @JsonIgnore
  @LastModifiedDate
  public Date getLastModifiedDate() {
    return lastModifiedDate;
  }

  @Version
  @Column
  public Long getVersion() {
    return version;
  }
Run Code Online (Sandbox Code Playgroud)

通过文档,这应该给我一个Etag价值?如图书馆的片段所示

protected HttpHeaders prepareHeaders(PersistentEntity<?, ?> entity, Object value) {

    // Add ETag
    HttpHeaders headers = ETag.from(entity, value).addTo(new HttpHeaders());

    // Add Last-Modified
    AuditableBeanWrapper wrapper = getAuditableBeanWrapper(value); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-data spring-data-jpa spring-data-rest

11
推荐指数
2
解决办法
3876
查看次数

Springboot:BeanDefinitionStoreException:无法解析配置类

我试图通过运行使用maven创建的jar并执行下面的异常来执行我的springboot应用程序,这在很多尝试之后都没有得到解决.任何帮助或指针将不胜感激.

提前致谢.

请在下面找到异常跟踪.

 2016-01-28 11:35:42.034  INFO 3732 --- [           main] Application                              : Starting Application on DFWLW72RTG262 with PID 3732 (C:\project\RestSpringBoot\target\springboot-0.0
.1-SNAPSHOT.jar started by vaigupta in C:\project\RestSpringBoot\target)
2016-01-28 11:35:42.123  INFO 3732 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7
d7cd6ad: startup date [Thu Jan 28 11:35:42 CST 2016]; root of context hierarchy
2016-01-28 11:35:42.149  WARN 3732 --- [           main] ionWarningsApplicationContextInitializer :

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.


2016-01-28 11:35:48.607  WARN …
Run Code Online (Sandbox Code Playgroud)

spring spring-security maven spring-data spring-boot

11
推荐指数
3
解决办法
5万
查看次数

Spring Data JDBC/Spring Data JPA vs Hibernate

什么是典型的现实生活场景,人们会选择Spring Data JDBC/Spring Data JPA vs Hibernate?我想了解其中任何一种实现最适合的场景.

hibernate spring-data spring-data-jpa spring-data-jdbc

11
推荐指数
2
解决办法
2万
查看次数

JPA:将空的Fetch结果加入NULL空

我在User和GameMap之间有一对多的关系.一个用户可以拥有许多地图.

用户类:

// LAZY LOADED
@OneToMany(cascade = CascadeType.ALL, mappedBy = "creater")
private final List<GameMap> maps = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

但是,有时我需要急于加载地图.为了避免在关闭Session之后出现LazyInitializationException,我有两种检索用户的变体.

用户存储库:

public interface UserRepository extends JpaRepository<User, Long> {

    Optional<User> findById( Long id );

    @Query("SELECT u FROM User u JOIN FETCH u.maps WHERE u.id = (:id)")
    public User findByIdEagerFetch( @Param("id") Long id );
}
Run Code Online (Sandbox Code Playgroud)

问题:
但是,如果表中没有此用户的映射,则JPQL JOIN FETCH变量可以在一个用户中执行,并且如果该用户没有映射,则他的映射将返回NULL用户.

问题:
如何重写JPQL语句以便检索用户并可选地(!)所有他的地图,但如果没有地图,那可以,但不要返回NULL用户.

java hibernate jpa lazy-loading spring-data

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

架构'SA'不存在并且丢弃表

我正在使用Spring Boot创建课程和主题数据库.一旦我对课程课程进行了更改,我就遇到了一堆错误.我不确定是什么问题.以下是错误消息:

 ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table course drop constraint FKokaxyfpv8p583w8yspapfb2ar

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Schema 'SA' does not exist

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop table course

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Schema 'SA' does not exist

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop table topic

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Schema 'SA' does not exist

    WARN 1136 --- …
Run Code Online (Sandbox Code Playgroud)

java spring spring-data spring-boot

11
推荐指数
2
解决办法
6775
查看次数

Spring/Hibernate:双向映射,不同步JPQL查询

在实体之间的双向映射(例如@ManyToOne@OneToMany)中,对方需要在每次更改时进行同步,尤其是在使用第二级缓存时.这通常使用辅助方法完成.如果Many部件包含大量条目,那么这些辅助方法不能很好地执行,因为每次都会获取整个集合.一个简单的例子是一个实体Store,它有n Products,但n非常大.添加新ProductStore将需要Store获取整个列表Products,终于将其添加到组(见下面的代码示例).

有人可能会争辩说,在对这种关系进行建模时,可以更好地用从单向关联Product来表示Store.我们在应用程序中使用了很多JPQL查询.在JPQL中,从双方加入实体非常方便.

@OneToManyStore实体中映射关系时是否看到任何问题,Many实际上意味着很多而不仅仅是少数几个,只要让整个关系被懒惰地取出,只是让字段保密,没有getter和setter?据我所知,Hibernate只需要字段来映射关系.如果该集是私有的,那么不会出现性能问题?


Product实体:

@Entity
@Table(name = "product")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Product {

  @ManyToOne(fetch = FetchType.LAZY)
  private Store store;

  // setter, getter, helper methods
}
Run Code Online (Sandbox Code Playgroud)

Store实体:

@Entity
@Table(name = "store")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Store { …
Run Code Online (Sandbox Code Playgroud)

java entity hibernate jpql spring-data

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

使用Spring Data-JPA更新单向@OneToMany对象列表时的常见行为是什么?

我有一个带有另一个对象列表的对象.它映射如下:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "products")
public class Product extends DateAudit {
    private static final long serialVersionUID = 1L;

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

    @NotBlank
    @Size(min = 3, max = 30)
    private String name;

    @NotBlank
    private String shortDescription;

    @NotBlank
    private String description;

    @NotNull
    private Double regularPrice;

    private Double promotionPrice;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", nullable = false)
    private Category category;

    @NotNull
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "store_id", nullable = false)
    private Store store;

    @Size(max …
Run Code Online (Sandbox Code Playgroud)

java hibernate one-to-many spring-data

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