gpt4 book ai didi

java - 加入 hibernate 状态

转载 作者:行者123 更新时间:2023-12-02 06:58:17 26 4
gpt4 key购买 nike

我正在使用 Java 和 Hibernate 3。

我有一个sql如下:

select sd3.id as id_3, sd2.id as id_2, sd1.id as id_1, od.id as id_0 from developer as sd3 
left outer join developer as sd2 on sd3.sr_developer_id = sd2.id
left outer join developer as sd1 on sd2.sr_developer_id = sd1.id
left outer join developer as od on sd1.sr_developer_id = od.id
where sd3.id = 812

这是一个自连接的情况。

表结构如下:

开发人员

id  | sr_developer_id
---------------------
812 | 463
463 | 8
8 | NULL

上述查询的输出是:

id_3 | id_2 | id_1 | id_0
--------------------------
812 | 463 | 8 | NULL

现在我想在 HQL 或条件中转换此查询。谁能帮我吗?

编辑:-

Developer.java

private long id;
private long srDeveloperID;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public long getSrDeveloperID() {
return srDeveloperID;
}

public void setSrDeveloper(long srDeveloperID) {
this.srDeveloperID = srDeveloperID;
}

Developer.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping >
<class name="com.beans.Developer" table="developer">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="srDeveloperID" column="sr_developer_id" type="long"></property>
</class>
</hibernate-mapping>

最佳答案

试试这个......

按原样输入您的查询(即选择......................id=812)@“您的查询”;

{
String sql = "Your Query";
SQLQuery query = session.createSQLQuery(sql);

query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
return query.list();
}

关于java - 加入 hibernate 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17018017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com