hibernate 变态问题

mamlong 发布于 2013/05/15 20:18
阅读 4K+
收藏 0

我有个TelphoneBean 和数据库了的 telephone_infor 表映射。

当hql = ="from TelphoneBean"去查询,不报错。但是当hql="from TelphoneBean as tp where tp.id='0000000002'"去查询数据库时,执行到Query query = session.createQuery(hql);报空指针。注(其他表的操作不管加不加where条件都不报错)

报错如下:

2013-5-15 19:53:38 org.hibernate.cfg.Environment <clinit>
信息: Hibernate 3.3.2.GA
2013-5-15 19:53:38 org.hibernate.cfg.Environment <clinit>
信息: hibernate.properties not found
2013-5-15 19:53:38 org.hibernate.cfg.Environment buildBytecodeProvider
信息: Bytecode provider name : javassist
2013-5-15 19:53:38 org.hibernate.cfg.Environment <clinit>
信息: using JDK 1.4 java.sql.Timestamp handling
2013-5-15 19:53:38 org.hibernate.cfg.Configuration configure
信息: configuring from resource: /hibernate.cfg.xml
2013-5-15 19:53:38 org.hibernate.cfg.Configuration getConfigurationInputStream
信息: Configuration resource: /hibernate.cfg.xml
2013-5-15 19:53:38 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/SupplierBean.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.SupplierBean -> supplier_infor
2013-5-15 19:53:39 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/TelPhoneBean.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.TelphoneBean -> telephone_infor
2013-5-15 19:53:39 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/StaffBean.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.StaffBean -> staff_infor
2013-5-15 19:53:39 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/VipBean.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.VipBean -> vip_infor
2013-5-15 19:53:39 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/OrderBean.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.OrderBean -> order_infor
2013-5-15 19:53:39 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/Vipordernumandtotalpriceview.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.Vipordernumandtotalpriceview -> vipordernumandtotalpriceview
2013-5-15 19:53:39 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/mml/telshop/domain/OrderDetailBean.hbm.xml
2013-5-15 19:53:39 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.mml.telshop.domain.OrderDetailBean -> order_detail_infor
2013-5-15 19:53:39 org.hibernate.cfg.Configuration doConfigure
信息: Configured SessionFactory: null
2013-5-15 19:53:39 org.hibernate.mapping.RootClass checkCompositeIdentifier
警告: composite-id class does not override equals(): com.mml.telshop.domain.TelphoneBean
2013-5-15 19:53:39 org.hibernate.mapping.RootClass checkCompositeIdentifier
警告: composite-id class does not override hashCode(): com.mml.telshop.domain.TelphoneBean
2013-5-15 19:53:39 org.hibernate.mapping.RootClass checkCompositeIdentifier
警告: composite-id class does not override equals(): com.mml.telshop.domain.OrderDetailBean
2013-5-15 19:53:39 org.hibernate.mapping.RootClass checkCompositeIdentifier
警告: composite-id class does not override hashCode(): com.mml.telshop.domain.OrderDetailBean
2013-5-15 19:53:39 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: Using Hibernate built-in connection pool (not for production use!)
2013-5-15 19:53:39 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: Hibernate connection pool size: 20
2013-5-15 19:53:39 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: autocommit mode: false
2013-5-15 19:53:39 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/telephoneshop
2013-5-15 19:53:39 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: connection properties: {user=root, password=****}
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: RDBMS: MySQL, version: 5.5.23
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.8 ( Revision: ${svn.Revision} )
2013-5-15 19:53:39 org.hibernate.dialect.Dialect <init>
信息: Using dialect: org.hibernate.dialect.MySQLDialect
2013-5-15 19:53:39 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
信息: Using default transaction strategy (direct JDBC transactions)
2013-5-15 19:53:39 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
信息: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Automatic flush during beforeCompletion(): disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Automatic session close at end of transaction: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: JDBC batch size: 15
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: JDBC batch updates for versioned data: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Scrollable result sets: enabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: JDBC3 getGeneratedKeys(): enabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Connection release mode: auto
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Maximum outer join fetch depth: 2
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Default batch fetch size: 1
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Generate SQL with comments: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Order SQL updates by primary key: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Order SQL inserts for batching: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
信息: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2013-5-15 19:53:39 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
信息: Using ASTQueryTranslatorFactory
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Query language substitutions: {}
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: JPA-QL strict compliance: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Second-level cache: enabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Query cache: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory createRegionFactory
信息: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Optimize cache for minimal puts: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Structured second-level cache entries: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Echoing all SQL to stdout
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Statistics: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Deleted entity synthetic identifier rollback: disabled
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Default entity-mode: pojo
2013-5-15 19:53:39 org.hibernate.cfg.SettingsFactory buildSettings
信息: Named query checking : enabled
2013-5-15 19:53:39 org.hibernate.impl.SessionFactoryImpl <init>
信息: building session factory
2013-5-15 19:53:40 org.hibernate.impl.SessionFactoryObjectFactory addInstance
信息: Not binding factory to JNDI, no JNDI name configured
from TelphoneBean b where b.telBrand=?
java.lang.NullPointerException
 at org.hibernate.util.StringHelper.root(StringHelper.java:257)
 at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1391)
 at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
 at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1367)
 at org.hibernate.hql.ast.tree.FromElement.getIdentityColumn(FromElement.java:320)
 at org.hibernate.hql.ast.tree.IdentNode.resolveAsAlias(IdentNode.java:154)
 at org.hibernate.hql.ast.tree.IdentNode.resolve(IdentNode.java:100)
 at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117)
 at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113)
 at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:854)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4603)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExprLhs(HqlSqlBaseWalker.java:5067)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4528)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1289)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3722)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1864)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:818)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:604)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)
 at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)
 at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
 at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
 at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
 at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
 at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
 at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
 at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
 at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
 at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
 at com.mml.telshop.hibernate.HibernateUtil.executeQuery(HibernateUtil.java:167)
 at com.mml.houtai.telshop.junit.SupplierPhoneHbmXmlTest.main(SupplierPhoneHbmXmlTest.java:37)
Exception in thread "main" java.lang.RuntimeException
 at com.mml.telshop.hibernate.HibernateUtil.executeQuery(HibernateUtil.java:179)
 at com.mml.houtai.telshop.junit.SupplierPhoneHbmXmlTest.main(SupplierPhoneHbmXmlTest.java:37)
弄了很久,也上网查了很多资料。但是都没有等到解决。希望在开源中国,能得到解决。毕设急用!希望大家能耐心帮忙看看,在此先谢谢大家了。

另外:当换成Query query = session.createSQLQuery(sql);sql="select *from telephone_infor as tp where tp.id='0000000002'";能查询。

 

加载中
0
anying
anying
是不是 as 问题. 去掉看看
mamlong
mamlong
问题就在于这个id 属性。我把属性id改成 telId问题就解决。所以我认为95%是这个id属性造成的。再次谢谢你,祝你工作顺利!
mamlong
mamlong
谢谢你的热心。不是as问题。在我不段的尝试下,问题我已经解决了。造成这个问题的原因是:TelphoneBean 有个属性--private String id;hibernate 映射文件中:<property name="id" column="id" type="java.lang.String"/>。
0
mamlong
mamlong

谢谢你的热心。不是as问题。在我不段的尝试下,问题我已经解决了。造成这个问题的原因是:TelphoneBean 有个属性--private String id,telephone_infor 表中有个字段--id;hibernate 映射文件中:<property name="id" column="id" type="java.lang.String"/>。

问题就在于这个id 属性。不知道是不是id这个属性引起的。反正我把属性id改成 telId问题就解决。所以我认为95%是这个id属性造成的。再次谢谢你,祝你工作顺利!

0
不是小白
不是小白
hibernate 中有一个BUG,就是主键如果名字一样,会覆盖~~~~
返回顶部
顶部