在JPA查询中使用@Transient访问字段

Cuo*_* Le 3 jpql

我有一个具有transient属性的实体:

@Entity
@Table(name = "asset")
public class Asset {
    @Transient
    private String locationIdentifier = "N/A";

    @SuppressWarnings("unused")
    @PostLoad
    private void onPostLoad() {
        if (location != null) {
            locationIdentifier = location.getIdentifier();
        }
    }

   [other stuffs]

   }
Run Code Online (Sandbox Code Playgroud)

我试图locationIdentifier在JPA中访问这种方式:

String sqlString = "SELECT asset FROM Asset WHERE asset.locationIdentifier = :inputstr";
Query query = entityManager.createQuery(sqlString);
Run Code Online (Sandbox Code Playgroud)

但是我收到了一个错误: Cannot resolve the property locationIdentifier

我想问一下如何locationIdentifier使用JPQL 访问?

对不起我的英语不好.提前致谢!

Mik*_*unu 7

JPQL查询转换为SQL查询,SQL查询操作数据库中的数据.标记属性瞬态意味着属性不会持久保存到数据库,因此无法从数据库中查询.