我有2個實體:DocumentEntity (docNumber (primary key), dateOfFill, ...)
和FileEntity (id, title, size, ...)
。我有一個HQL查詢與內部聯接的2,應在Oracle數據庫上運行:如何內部加入休眠兩個獨立的實體
String queryStr = "SELECT docNumber " +
+ "FROM DocumentEntity d " +
+ "INNER JOIN FileEntity f " +
+ "ON d.docNumber = f.title " +
+ "WHERE d.date > to_date('01.01.2011','dd.mm.yyyy')"
Query query = em.createQuery(query_string);
return query.getResultList();
當我運行的代碼片段,我得到一個例外org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!
我通過
-
看着
- Hibernate 4.3.6 QuerySyntaxException: Path expected for join
- HQL ERROR: Path expected for join
- Path Expected for Join! Nhibernate Error
- HQL Hibernate INNER JOIN
但沒有解決我的問題。建議的路徑不能用在這個例子中(至少它給出了錯誤的路徑錯誤)。最後一個鏈接的答案是這樣的:
連接只能在實體之間存在關聯時使用。
問題是我不能關聯這兩個實體。
問題是: 如何加入這兩個實體?
UPDATE: 我的實體是:
@Entity
@Table(name = "DOCUMENT")
public class DocumentEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "DOC_NUMBER", nullable = false)
private String docNumber;
@Basic(optional = false)
@Column(name = "DATE_OF_FILL")
@Temporal(TemporalType.DATE)
private Date dateOfFill;
...
}
和
@Entity
@Table(name = "FS_FILE")
public class FileEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "FS_FILE_SEQ", allocationSize = 1, sequenceName = "FS_FILE_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FS_FILE_SEQ")
@Column(name = "ID", nullable = false)
protected Long id;
@Column(name = "TITLE", nullable = false)
protected String title;
@Column(name = "MIMETYPE", nullable = false)
protected String mimetype;
@Column(name = "FILESIZE", nullable = false)
protected Long filesize;
@Column(name = "FILEPATH", nullable = false)
protected String filepath;
...
}
你能顯示你的兩個實體的配置嗎? – davidxxx
@davidhxxx:你究竟是什麼意思?你想看到什麼? – Armine
您的實體... – davidxxx