HQL 中的无效路径和奇怪的替换

Invalid path in HQL and weird substitutions

我希望你能帮助我。

我正在努力将 DSpace 的自定义安装从 5.5 升级到 6.3,我 运行 遇到了一个奇怪的 HQL 问题。

我要实现的SQL是这样的:

SELECT bt.* FROM bitstream AS bt 
    INNER JOIN authorprofile2bitstream AS ap2b 
    ON bt.bitstream_id=ap2b.bitstream_legacy_id 
    WHERE ap2b.authorprofile_id='xxx';

这是我在代码中编写的 HQL,它应该做同样的事情:

SELECT bt FROM Bitstream bt, AuthorProfile2Bitstream ap2b 
    WHERE bt.legacyId=ap2b.bitstream_legacy_id AND AuthorProfile2Bitstream.authorprofile_id=:apid

这是它引发的错误:

org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: '8.authorprofile_id' [SELECT bt FROM org.dspace.content.Bitstream bt, org.dspace.content.AuthorProfile2Bitstream ap2b WHERE bt.legacyId=ap2b.bitstream_legacy_id AND AuthorProfile2Bitstream.authorprofile_id=:apid]


第一个问题: 为什么要将 AuthorProfile2Bitstream 更改为 8?

第二: 如果正确找到 AuthorProfile2Bitstream class(根据异常中显示的扩展查询) ,然后再问#1。

第三:这是表示连接的方式吗?

提前致谢,

这些是我的 classes:

比特流

@Entity
@Table(name="bitstream")
public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport
{
    @Column(name="bitstream_id", insertable = false, updatable = false)
    private Integer legacyId;

    @Column(name = "sequence_id")
    private Integer sequenceId = -1;

    @Column(name = "checksum", length = 64)
    private String checksum;

    @Column(name = "checksum_algorithm", length = 32)
    private String checksumAlgorithm;

    @Column(name = "size_bytes")
    private long sizeBytes;

    @Column(name = "deleted")
    private boolean deleted = false;

    @Column(name = "internal_id", length = 256)
    private String internalId;

    @Column(name = "store_number")
    private int storeNumber;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "bitstream_format_id")
    private BitstreamFormat bitstreamFormat;

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "bitstreams")
    private List<Bundle> bundles = new ArrayList<>();

    @OneToOne(fetch = FetchType.LAZY, mappedBy="logo")
    private Community community;

    @OneToOne(fetch = FetchType.LAZY, mappedBy="logo")
    private Collection collection;

AuthorProfile2Bitstream

@Entity
@Table(name="authorprofile2bitstream")
public class AuthorProfile2Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport
{

    @Column(name="id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private int id;
    
    @Column(name = "authorprofile_id")
    private UUID authorprofile_id;
    
    @Column(name = "bitstream_id")
    private UUID bitstream_id;
    
    @Column(name = "bitstream_legacy_id")
    private int bitstream_legacy_id;

这些是它们在数据库中的表示:

比特流

# \d bitstream
                                Table "public.bitstream"
       Column        |          Type          | Collation | Nullable |      Default
---------------------+------------------------+-----------+----------+-------------------
 bitstream_id        | integer                |           |          |
 bitstream_format_id | integer                |           |          |
 size_bytes          | bigint                 |           |          |
 checksum            | character varying(64)  |           |          |
 checksum_algorithm  | character varying(32)  |           |          |
 internal_id         | character varying(256) |           |          |
 deleted             | boolean                |           |          |
 store_number        | integer                |           |          |
 sequence_id         | integer                |           |          |
 uuid                | uuid                   |           | not null | gen_random_uuid()
Indexes:
    "bitstream_pkey" PRIMARY KEY, btree (uuid)
    "bitstream_id_unique" UNIQUE CONSTRAINT, btree (uuid)
    "bitstream_uuid_key" UNIQUE CONSTRAINT, btree (uuid)
    "bit_bitstream_fk_idx" btree (bitstream_format_id)
    "bitstream_id_idx" btree (bitstream_id)
Foreign-key constraints:
    "bitstream_bitstream_format_id_fkey" FOREIGN KEY (bitstream_format_id) REFERENCES bitstreamformatregistry(bitstream_format_id)
    "bitstream_uuid_fkey" FOREIGN KEY (uuid) REFERENCES dspaceobject(uuid)
Referenced by:
    TABLE "authorprofile2bitstream" CONSTRAINT "authorprofile2bitstream_bitstream_id_fkey" FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid)
    TABLE "bundle2bitstream" CONSTRAINT "bundle2bitstream_bitstream_id_fkey" FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid)
    TABLE "bundle" CONSTRAINT "bundle_primary_bitstream_id_fkey" FOREIGN KEY (primary_bitstream_id) REFERENCES bitstream(uuid)
    TABLE "checksum_history" CONSTRAINT "checksum_history_bitstream_id_fkey" FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid)
    TABLE "community" CONSTRAINT "community_logo_bitstream_id_fkey" FOREIGN KEY (logo_bitstream_id) REFERENCES bitstream(uuid)
    TABLE "most_recent_checksum" CONSTRAINT "most_recent_checksum_bitstream_id_fkey" FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid)
    TABLE "requestitem" CONSTRAINT "requestitem_bitstream_id_fkey" FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid)

AuthorProfile2Bitstream

# \d authorprofile2bitstream
                  Table "public.authorprofile2bitstream"
       Column        |  Type   | Collation | Nullable |      Default
---------------------+---------+-----------+----------+-------------------
 id                  | integer |           | not null |
 bitstream_legacy_id | integer |           |          |
 uuid                | uuid    |           | not null | gen_random_uuid()
 authorprofile_id    | uuid    |           |          |
 bitstream_id        | uuid    |           |          |
Indexes:
    "authorprofile2bitstream_pkey" PRIMARY KEY, btree (uuid)
    "authorprofile2bitstream_id_unique" UNIQUE CONSTRAINT, btree (uuid)
    "authorprofile2bitstream_uuid_key" UNIQUE CONSTRAINT, btree (uuid)
    "authorprofile2bitstream_authorprofile_idx" btree (authorprofile_id)
    "authorprofile2bitstream_bitstream_fk_idx" btree (bitstream_legacy_id)
    "authorprofile2bitstream_bitstream_idx" btree (bitstream_id)
Foreign-key constraints:
    "authorprofile2bitstream_authorprofile_id_fkey" FOREIGN KEY (authorprofile_id) REFERENCES authorprofile(uuid)
    "authorprofile2bitstream_bitstream_id_fkey" FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid)
    "authorprofile2bitstream_uuid_fkey" FOREIGN KEY (uuid) REFERENCES dspaceobject(uuid)

好吧,有时候你只需要看看你的东西张贴在某个地方或者为别人详细说明你自己就能得到答案。

我的错误是在 WHERE 子句中我没有引用 AuthorProfile2Bistream 实例 ap2b 而是 class 本身.

所以,正确的(现在有效的)HQL 查询是这样的

SELECT bt FROM Bitstream bt, AuthorProfile2Bitstream ap2b 
    WHERE bt.legacyId=ap2b.bitstream_legacy_id AND ap2b.authorprofile_id=:apid