Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1
I have following class:
Code:
/**
* Created by IntelliJ IDEA.
* @hibernate.class
*/
public class User implements Serializable {
private long userID;
private UserVersion baseUserVersion;
..... some more user fields like firsName, birthday e.tc
/**
* @hibernate.id generator-class="identity"
*/
public long getUserID() {
return userID;
}
public void setUserID(long userID) {
this.userID = userID;
}
/**
* @hibernate.many-to-one
* class="com.btf.um.entity.UserVersion"
* column="baseUserVersionID"
*/
public UserVersion getBaseUserVersion() {
return baseUserVersion;
}
public void setBaseUserVersion(UserVersion baseUserVersion) {
this.baseUserVersion = baseUserVersion;
}
For storing modification on user table i have created subclass UserVersion:
Code:
/**
* Created by IntelliJ IDEA.
* @hibernate.class
*/
public class UserVersion extends User{
private long userVersionID;
private UserVersion childVersion;
private User actualUser;
public UserVersion() {
}
public UserVersion(User actualUser) {
this.actualUser = actualUser;
setUser(actualUser);
}
/**
* @hibernate.many-to-one
* class="com.btf.um.entity.User"
* column="userID"
* not-null="true"
*/
public User getActualUser() {
return actualUser;
}
public void setActualUser(User actualUser) {
this.actualUser = actualUser;
}
/**
* @hibernate.many-to-one
* class="com.btf.um.entity.UserVersion"
* column="childVersionID"
*/
public UserVersion getChildVersion() {
return childVersion;
}
public void setChildVersion(UserVersion childVersion) {
this.childVersion = childVersion;
}
/**
* @hibernate.id generator-class="identity"
*/
public long getUserVersionID() {
return userVersionID;
}
public void setUserVersionID(long userVersionID) {
this.userVersionID = userVersionID;
}
public User getUser() {
return this;
}
public void setUser(User user) {
copyObjectValues(this, user);
}
}
Hibernate works absolutely decent on inserting or updating data in those tables, but i`m getting strange exception on excetuting following procedure
Code:
public List selectOtherUsersForPassport(String passportNum, String passportSeries, long userID) {
return getHibernateTemplate().find("from User u where u.passportNum = ? AND u.passportSeries=? AND u.userID!=? and u.deleted = false",
new Object[] {passportNum, passportSeries, userID});
}
Exception:
Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: userID of: com.btf.um.entity.UserVersion [
from com.btf.um.entity.UserVersion u where u.passportNum = ? AND u.passportSeries=? AND u.userID!=? and u.deleted = false]; nested
exception is org.hibernate.QueryException: could not resolve property: userID of: com.btf.um.entity.UserVersion [from com.btf.um.
entity.UserVersion u where u.passportNum = ? AND u.passportSeries=? AND u.userID!=? and u.deleted = false]
Caused by: org.hibernate.QueryException: could not resolve property: userID of: com.btf.um.entity.UserVersion [from com.btf.um.ent
ity.UserVersion u where u.passportNum = ? AND u.passportSeries=? AND u.userID!=? and u.deleted = false]
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)
at org.hibernate.hql.ast.FromElementType.getPropertyType(FromElementType.java:273)
at org.hibernate.hql.ast.FromElement.getPropertyType(FromElement.java:349)
at org.hibernate.hql.ast.DotNode.getDataType(DotNode.java:474)
at org.hibernate.hql.ast.DotNode.prepareLhs(DotNode.java:208)
at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:166)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:83)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:463)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:863)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3215)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1333)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:837)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:828)
at com.btf.um.dao.hbm.UserDaoImpl.selectOtherUsersForPassport(UserDaoImpl.java:101)
at com.btf.um.service.UMService.selectOtherUsersForPassport(Unknown Source)
at com.btf.um.service.UMService$$FastClassByCGLIB$$585ae255.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:709)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:100)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:647)
at com.btf.um.service.UMService$$EnhancerByCGLIB$$414d6173.selectOtherUsersForPassport(<generated>)
at com.btf.transfer.web.PayWizardController.referenceData(Unknown Source)
at org.springframework.web.servlet.mvc.AbstractWizardFormController.referenceData(AbstractWizardFormController.java:267)
at org.springframework.web.servlet.mvc.AbstractFormController.showForm(AbstractFormController.java:557)
at org.springframework.web.servlet.mvc.AbstractWizardFormController.showPage(AbstractWizardFormController.java:351)
at org.springframework.web.servlet.mvc.AbstractWizardFormController.processFormSubmission(AbstractWizardFormController.jav
a:513)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:250)
I cant realize why hibernate uses entity "com.btf.um.entity.UserVersion" instead of "com.btf.um.entity.User" and this is problem which brings excpetion i guess because procedure works fine if there is no "u.userID" property in query string.
Any help would be usefull. Thanx!