[英]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。
第三:這是表示連接的方式嗎?
提前致謝,
這些是我的課程:
比特流
@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;
作者簡介2Bitstream
@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)
作者簡介2Bitstream
# \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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.