我有两个模型类
Application.java
@Entity
@Table(name = "Application", catalog = "mysqldb")
@XmlRootElement
public class Application extends BaseObject implements Serializable {
private Long appId;
private Long userId;
private String name;
private String desc;
@Id
@Column(name = "AppId")
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getAppId() {
return this.appId;
}
public void setAppId(Long appId) {
this.appId = appId;
}
@Column(name = "userId", nullable = false)
public Long getUserId() {
return this.userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
@Column(name = "name", length = 128, nullable = false)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "Desc")
public String getDesc() {
return this.desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
User.java
@Entity
@Table(name="User",catalog="mysqldb")
@XmlRootElement
public class Client extends BaseObject implements Serializable {
private Long userId;
private String name;
@Id
@Column(name="userId")
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getUserId() {
return this.userId;
}
public void setClientId(Long clientId) {
this.clientId = clientId;
}
@Column(name="Name", length=128)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
我没有提到两者之间有任何关系。
我正在尝试获取具有用户ID的应用程序列表,并获取用户名。
在我的 ApplicationDaoImpl java类中,我有以下方法。
@Override
public List<ApplicationObj> getAllByUser(
Long userId) {
String queryString = "select application.appId as appId, application.userId as userId, user.name as name, application.name as name"
+ " from com.mydb.model.Application application join com.mydb.model.User user"
+ " with application.userId = user.userId"
+ " where application.userId=?";
Session session = getSession();
Query query = session.createQuery(queryString);
query.setParameter(0, userId);
List list = query.list();
return new ArrayList<ApplicationObj>();
}
我正在尝试获取结果并设置一个新对象。 (尚未设置为新对象。)
当我尝试执行此操作时,我收到以下异常
java.lang.IllegalStateException: DOT node with no left-hand-side!
at org.hibernate.hql.internal.ast.tree.DotNode.getLhs(DotNode.java:616)
at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:595)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:380)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3516)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3302)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3180)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735)
at com.mypgm.dao.hibernate.ApplicationDaoImpl.getAllByUser(ApplicationDaoImpl.java:74)
如何解决这个问题?或者如何在不映射任何关系的情况下进行连接查询