嗯,这个问题几乎说明了一切。如何使用JPARepository更新实体?
JPARepository只有一个保存方法,它不会告诉我它实际上是在创建还是在更新。例如,我向数据库用户插入一个简单的对象,该对象有三个字段:firstname、lastname和age
@Entity
public class User {
private String firstname;
private String lastname;
//Setters and getters for age omitted, but they are the same as with firstname an
我使用带有spring-data-jpa的oracle存储过程。在大多数情况下,当它是一个函数或输出参数是参数列表中的第一个时,它是非常好的。但是我有一些存储过程,其中输出param是param列表中的最后一个:
procedure get_data (some_val in varchar2 cur out sys_refcursor);
或返回多个输出引用,如
procedure get_my_data (cur1 out sys_refcursor, cur2 out sys_refcursor, some_val in varchar2);
有没有可能在JpaRepository中
我想创建一个从多个实体查询数据的“通用”存储库。如果我这么做了:
@Repository
public interface MyRepository {
@Query("select r from Role r")
List<Role> getRoles();
}
我得到一个错误,因为当需要一个MyRepository实例时,Spring找不到可以注入的实现。到现在为止还好。现在,如果我这样做:
@Repository
public interface MyRepository extends JpaRepository {
@Quer
我有spring应用程序,它使用PostgreSQL数据库使用spring-data-jpa连接,下面是我的实体,它有将近40个字段
现在,为了将实体保存到数据库中,我只是使用studentRepository.save方法
studentRepository.save(new StudentEntity());
DAO实体
@Table
@Entity
public class StudentEntity {
@Id
@Generate( using database sequenece)
private long studentId;
我决定将从1.3.2升级到1.4.0。不幸的是,这破坏了我使用@Query注释指定的几乎所有JPA查询。
例如
public interface MatchRepository extends JpaRepository<Match, MatchKey> {
// ...
@Query("SELECT min(m.hourOfTheMatch) FROM Match m WHERE m.primaryKey.matchday = :matchday")
DateTime getFirstMatchStartDateTime(Matchday
我知道的问题,但是使用org.springframework.data:spring-data-jpa:1.7.0.RELEASE我仍然有相同的问题(Either use @Param on all parameters except Pageable and Sort typed once, or none at all!)。我的课是:
public interface BalanceHistoryRepository extends JpaRepository<BalanceHistory, Long> {
@Query("select bh from Bala
我有一个有很多属性的模型。对于列表,我只想获得这些属性中的一小部分,因为它们中的大多数只在详细视图中显示。
因此,我为我的存储库编写了以下查询:
JpaRepository< Customer, Long >
@Query("SELECT id, name FROM Customer")
public List<Customer> findAllSummary();
它是有效的-确实返回了一个id和一个名称,但不是作为一个客户对象。当我将数据返回到JSON客户端时,这就成了一个问题:没有属性名称,只有每一行的值,而在默认查询中,也会返回名称,例如:
&
我使用Hibernate和JpaRepository来处理我的DB操作。
我有这个查询(为了简化,因为原始查询相当大):
@Query(value="select * from history h where h.project_id in :projects", nativeQuery=true)
List<History> getHistoriesByProjectsIn(@Param("projects")List<Long> projects);
当我传递有效而不是空的List<Long>时,它就起作用了。然而,当我传
我使用spring-data-jpa和querydsl (3.2.3)
我有一个基于用户filer/输入创建谓词集的场景。所有这些都会出现在BooleanExpression身上。
我的简化模型如下所示:
@Entity
public class Invoice {
@ManyToOne
private Supplier supplier;
}
@Entity
public class Supplier {
private String number;
}
@Entity
public class Company {
private String numbe
我使用了spring-data-jpa,并使用Specification类实现了动态查询。数据库的Sql Server版本为2019 有一个查询,我需要将日期时间(时间戳)截断为仅日期部分(没有时间),并应用where条件then。查询如下: select a from Table1 a where convert(DATE,date_col)>? 问题出在第一个参数,即DATE(this is actually a datatype and not a literal)。 我的代码在toPredicate方法中运行,描述如下: public Predicate toPredicate
我正在挑选一个项目,其中有一个JpaRepository实现,它在hibernate和Server之上使用Spring中的原生查询,返回一个列表。查询没有实现分页或限制。如果将全部结果集加载到内存中,我担心这会在生产中造成问题。
示例:
public interface MyEntityRepo extends JpaRepository<MyEntity,String> {
...
@Query(nativeQuery = true,
value = "SELECT t.name, t.date FROM MY_TABLE t WHERE t.condition =
我已经修改了一个现有的RESTful/JDBC应用程序,我必须使用Spring 4中的新特性。特别是JpaRepository。它将:
1)检索指定日期的事务列表。这个很好用
2)按类型检索指定日期的事务计数。这不像预期的那样有效。查询的设置类似,但实际返回类型非常不同。我对每个查询都有POJO。
我的事务JPA存储库如下所示:
public interface MyTransactionsRepository extends JpaRepository<MyTransactions, Long>
//My query works like a charm.
@Query( v
我有一个带有查询注释的Spring回购,如下所示:
@Repository
public interface MainRepository
extends
JpaRepository<MainEntity, MainEntity.ID>,
JpaSpecificationExecutor<MainEntity> {
@Query("select e.start, e.finish,e.forename,e.surname from MainEntity e where e.volunteerId= :id "
我正在做一个弹簧引导实验,并使用MySQL。
例如,如果我有一个用户列表,但我想获得指定的名称,那么如何编写只表示这种情况的SQL查询呢?
这是我的模特课:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name="users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long id;
@Column(nam
我使用spring-data-jpa运行本机postgres查询。查询是对实体的jsonb数据执行的。我可以在db服务器上成功地运行原始查询:
SELECT e.*
FROM public.entity e where e.json ? 'salary' and e.json ->> 'salary' > '10000';
但是,由于spring-data-jpa也支持参数化查询的?,所以在查询的语法中似乎存在冲突,因此应用程序最终甚至无法启动。
@Query(value = "select e.* from Enti
我想对枚举列执行如下like查询:
@Repository
public interface StudentRepository extends JpaRepository<Student, String>
{
@Query("SELECT u FROM Student u WHERE u.house LIKE :namePrefix% ")
Page<Student> getStudentWithMatchingHouseNamePrefix(@Param("namePrefix")