春季数据中的@Transient 不起作用

2022-01-18 00:00:00 spring java Hibernate jpa spring-data

我有结算实体

@Entity
@Table(name = "settlement")
public class Settlement {

    @ManyToOne
    @JoinColumn(name = "subscription_x_product_id")
    private ProductSubscription productSubscription;

ProductSubscription实体相关的

@Entity
@Table(name = "subscriptionproduct")
public class ProductSubscription {
    @ManyToOne
    @JoinColumn(name = "product_id")
    private Product product;

Product实体相关的

@Entity
public class Product {
    @Transient
    private String enabled;

Product 实体中,我有字段 enabled@org.springframework.data.annotation.Transient 注释.我也有存储库

in Product entity i have field enabled which annotated with @org.springframework.data.annotation.Transient. also I have Repository

public interface SettlementRepository extends JpaRepository<Settlement, Integer>

当我调用 SettlementRepository.findAll(); 它给出异常 Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'enabled'.

when I call SettlementRepository.findAll(); it give exception Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'enabled'.

如何忽略从数据库加载的 enabled 字段?

How can I ignore the enabled field from being loaded from the DB ?

推荐答案

我找到了解决办法,问题出在Annotation @org.springframework.data.annotation.Transient 一次我改成@javax.persistence.Transient效果很好.

I found the solution, the problem was in Annotation @org.springframework.data.annotation.Transient once I changed to @javax.persistence.Transient it worked fine.

相关文章