Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更新查询spring数据JPA修改所有列_Java_Postgresql_Spring Boot_Java 8_Spring Data Jpa - Fatal编程技术网

Java 更新查询spring数据JPA修改所有列

Java 更新查询spring数据JPA修改所有列,java,postgresql,spring-boot,java-8,spring-data-jpa,Java,Postgresql,Spring Boot,Java 8,Spring Data Jpa,我正在尝试根据用户从UI传递的Id更新表 问题陈述示例:当用户将Id作为1发送时,应仅使用其他几个参数(如lastModifiedBy和Delete)更新表中的一行,其中“我的代码”将更新表中的所有行 orm.xml <entity class="com.example.Domain" name="Domain"> <table name="t_table"/> <attributes> <id name="id">

我正在尝试根据用户从UI传递的Id更新表

问题陈述示例:当用户将Id作为1发送时,应仅使用其他几个参数(如lastModifiedBy和Delete)更新表中的一行,其中“我的代码”将更新表中的所有行

orm.xml

<entity class="com.example.Domain" name="Domain">
    <table name="t_table"/>
    <attributes>
        <id name="id">
            <column name="ID" nullable="false"/>
            <generated-value strategy="SEQUENCE" generator="S_GEN"/>
            <sequence-generator name="S_GEN" sequence-name="S_GEN" allocation-size="1"/>
        </id>
        <basic name="deleted">
            <column name="DELETED" nullable="false" length="5"/>
        </basic>
        <basic name="lastModifiedBy">
            <column name="LAST_MODIFIED_BY" nullable="false" length="100"/>
        </basic>
    </attributes>
JPA存储库:

    public interface JpaDomainRepository extends Repository<Domain, Long> {
        @Modifying
        @Query(value = "update Domain set DELETED = true, LAST_MODIFIED_BY = lastModifiedBy where id = id")
        int update(Domain domain);
}   
若表已经有多个条目,并且我正在尝试更新第一行,那个么其余所有行都将被修改

简而言之,对于下面的where子句,我的update查询始终为true

例如,对于输入1,只有id=1的一列应该得到修改,但查询也在修改第2行、第3行等等

update Domain set DELETED = true, LAST_MODIFIED_BY = lastModifiedBy where 1= 1
为什么会这样?解决方案是什么

附言:
我不想从服务类显式传递ID,因为我的ID在域对象中已经可用。

其中ID=ID将始终为true,如果您使用的正是这种语法。。。你是说别的吗

@Query中的参数不应该前面加上?对于索引参数和:对于命名参数

   @Query(value = "update Domain set DELETED = true, LAST_MODIFIED_BY = :lastModifiedBy where id = :id")

我已在域对象中具有id。1.传递未使用的域对象的意义是什么:为什么不简单地传递ID?2.为什么您要编写一个查询来执行更新,而不是使用标准ORM功能,在这里您可以通过继承的
save(entity)
方法进行更新,如果您扩展了
crudepository
而不是tahn
Repository
@AlanHay 1,您将可以使用该方法。拥有域对象的点是2。我之所以编写查询,是因为我使用的是spring数据jpa.1。您没有编写本机查询:这是一个JPQL查询。2.拥有域对象的点是……——我认为您需要回顾一下JPA的一些基本概念。@AlanHay传递完整的域对象而不是传递多个参数,这不是一个好方法吗?我希望您理解我的问题陈述,如果您在更新方法中实际使用它,那将是一个问题。但你不;(我正在寻找SpEL解决方案,并在该URL中找到
update Domain set DELETED = true, LAST_MODIFIED_BY = lastModifiedBy where 1= 1
   @Query(value = "update Domain set DELETED = true, LAST_MODIFIED_BY = :lastModifiedBy where id = :id")