我有一个标准的POJO,里面有一组属性.POJO已注释为a @Document,以便作为Document保存在MongoDB中.
如何(注释??)可以忽略/避免POJO中的某个属性被保留?
我正在尝试实现自定义Spring存储库.我有界面:
public interface FilterRepositoryCustom {
List<User> filterBy(String role);
}
Run Code Online (Sandbox Code Playgroud)
实施:
public class FilterRepositoryImpl implements FilterRepositoryCustom {
...
}
Run Code Online (Sandbox Code Playgroud)
和"主"存储库,扩展我的自定义存储库:
public interface UserRepository extends JpaRepository<User, String>, FilterRepositoryCustom {
...
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Spring Boot,根据文档:
默认情况下,Spring Boot将启用JPA存储库支持并查看@SpringBootApplication所在的包(及其子包).
当我运行我的应用程序时,我收到此错误:
org.springframework.data.mapping.PropertyReferenceException:找不到类型User的属性filterBy!
我正在使用Spring Data Redis和Jedis.我试图用密钥存储哈希vc:${list_id}.我能够成功插入redis.但是,当我使用redis-cli检查按键时,我看不到按键vc:501381.相反,我明白了\xac\xed\x00\x05t\x00\tvc:501381.
为什么会发生这种情况?如何更改?
我目前正在开发一个使用Spring Boot和Spring Data(它的JpaRepository接口准确)和Hibernate的应用程序.
我喜欢Hiberante的一个方面是它的缓存功能 - 当你提交与特定对象匹配的多个查询时,你将在每次查询执行时返回该对象的相同实例(相对于Java的==运算符).但是,在使用Spring Data和JpaRepository类时,情况似乎并非总是如此.出于这个原因,我假设这里有多个HibernateSession实例在工作.
因此我的问题是:Spring Data如何处理Hibernate会话?什么时候打开或关闭它们?有没有办法将它配置为对我的应用程序的整个运行时使用相同的会话来充分利用Hibernate的对象缓存?有没有理由不这样做?
谢谢,
艾伦
我正在使用Spring data jpa repositories,要求提供不同字段的搜索功能.搜索之前输入的字段是optional.I有5场说EmployeeNumber,Name,Married,Profession和DateOfBirth.
这里我只需要用户查询给定的值,其他字段应该被忽略.Ex,
Input : EmployeeNumber: ,Name:St,Married: ,Professsion:IT,DateOfBirth:
Query : Select * from Employee e where Name like 'St%' and Profession like 'IT%';
Input : EmployeeNumber:10,Name: ,Married: ,Professsion:IT,DateOfBirth:
Query : Select * from Employee e where EmployeeNumber like '10%' and Profession like 'IT%';
Run Code Online (Sandbox Code Playgroud)
所以我们在这里考虑输入和查询的值.在这种情况下,春季数据是具有限制中提到的这篇文章(不可扩展,所有可能出现的问题,应书面)我使用的Querydsl,但仍存在问题,null待开发领域应该被忽略,几乎所有可能的查询需要.在这case 31 queries.如果搜索字段是6,7,8...??
使用可选字段实现搜索选项的最佳方法是什么?
在以下之间使用Spring Data JPA关键字时是否有任何区别:
List<SomeEntity> findBySomeCondition();
Run Code Online (Sandbox Code Playgroud)
和
List<SomeEntity> findAllBySomeCondition();
Run Code Online (Sandbox Code Playgroud) 我尝试在ASC上按顺序在表上创建一个Spring-Data-JPA应用程序,但它给了我一个错误:
Invalid derived query! No property asc found for type java.util.Calendar
Run Code Online (Sandbox Code Playgroud)
为什么?
List<Foo> findAllOrderByDateAsc();
Run Code Online (Sandbox Code Playgroud)
要么
@Query("SELECT * FROM foo ORDER BY date ASC")
List<Foo> findAllOrderByDateAsc();
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Spring Data JPA 1.8与Java 8 Date/Time API JSR-310一起使用.
一切似乎都有效,直到我试图让所有车辆在两个LocalDateTimes之间.返回的实体数量似乎只与它应该的数量松散相关.
@Repository
public interface VehicleRepository extends JpaRepository<Vehicle, Long> {
List<Vehicle> findByDateTimeBetween(LocalDateTime begin, LocalDateTime end);
}
Run Code Online (Sandbox Code Playgroud)
@Entity
@Table(name = "VEHICLE")
public class Vehicle implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "IDX", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.AUTO)
private long vehicleId;
@Column(name = "DATE_TIME", nullable = false)
private LocalDateTime dateTime = LocalDateTime.now();
// Getters and Setters
}
Run Code Online (Sandbox Code Playgroud)
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.0.RELEASE</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我想在存储库层中编写一些查询方法.此方法必须忽略null参数.例如:
List<Foo> findByBarAndGoo(Bar barParam, @optional Goo gooParam);
Run Code Online (Sandbox Code Playgroud)
此方法必须通过以下条件返回Foo:
bar == barParam && goo == gooParam;
Run Code Online (Sandbox Code Playgroud)
如果gooParam不为null.如果gooParam为null,则条件更改为:
bar == barParam;
Run Code Online (Sandbox Code Playgroud)
有什么解决方案吗?有人能帮我吗?
我有spring-data和hibernate配置并运行.我可以使用spring-data保存记录但由于某种原因,我无法运行将更新表中所有布尔字段的查询.
我试过这个:
@Query("update Content v set v.published = false where v.division = :division and v.section = :section")
void unPublishContent(@Param("division") String division,
@Param("section") String section);
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
@Query("update Content v set v.published = 0 where v.division = :division and v.section = :section")
void unPublishContent(@Param("division") String division,
@Param("section") String section);
Run Code Online (Sandbox Code Playgroud)
参数division和section正在实现,但表中没有变化.
ps我也在使用mysql数据库.