我希望你能幫我解決這個問題。
我正在將 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類(根據例外中顯示的擴展查詢),那么再次提問 #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;
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;
這些是它們在 DB 中的表示:
位元流
# \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)
uj5u.com熱心網友回復:
好的,確實有時您只需要查看發布在某處的內容或詳細說明其他人即可自行獲得答案。
我的錯誤是在 WHERE 子句中我沒有參考AuthorProfile2Bistream實體ap2b而是類本身。
所以,正確的(并且現在作業的)HQL 查詢是這樣的
SELECT bt FROM Bitstream bt, AuthorProfile2Bitstream ap2b
WHERE bt.legacyId=ap2b.bitstream_legacy_id AND ap2b.authorprofile_id=:apid
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/467439.html
標籤:爪哇 sql PostgreSQL 休眠 空间
