当我在休眠中编写更新查询时。我收到这个错误。我正在使用 Hibernate 3.2 和 MySQL 5.0。在 UserDetails.java 中,Login 是外键引用 Login.java 的主键 (loginId)。
java.lang.NullPointerException
at org.hibernate.hql.ast.util.SessionFactoryHelper.findSQLFunction(SessionFactoryHelper.java:342)
at org.hibernate.hql.ast.tree.IdentNode.getDataType(IdentNode.java:266)
at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.extractDataType(BinaryLogicOperatorNode.java:168)
at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.initialize(BinaryLogicOperatorNode.java:34)
at org.hibernate.hql.ast.HqlSqlWalker.prepareLogicOperator(HqlSqlWalker.java:1007)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3992)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:358)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
这是服务类
Date birthDay = formatter1.parse(brthDay);
session = HibernateUtil.getSession();
transaction = session.beginTransaction();
Login login = (Login) session.get(Login.class, loginId);
Query query2 = session.createQuery("update UserDetails set name=:Name, secEmailId=:SecEmailId, dob=:DOB, gender=:Gender where Login=:LoginId");
query2.setString("Name", name);
query2.setString("SecEmailId", secEmailId);
query2.setDate("DOB", birthDay);
query2.setString("Gender", gender);
query2.setParameter("LoginId", login);
profileUpdated = query2.executeUpdate();
这是 UserDetails.java pojo 类
private Long udid;
private Login login;
private String name;
private String secEmailId;
private Date dob;
private String gender;
private long createrId;
private Date createdDate;
private long updaterId;
private Date updatedDate;
settes & getters