先生,我想从数据库中获取数据并使用hql而不是sql在hibernate中打印,我已经尝试了一些教程,但我无法得到正确答案请提供解决方案
private void pwdActionPerformed(java.awt.event.ActionEvent evt) {
Session session = HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery("FROM Users U WHERE U.pwd='admin'");
List list = query.list();
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
先生,请尽快回答这个问题
91 [AWT-EventQueue-0] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
96 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
98 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - hibernate.properties not found
101 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
104 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
147 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
147 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
188 [AWT-EventQueue-0] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
207 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/PatientDetail.hbm.xml
296 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/PatientVisit.hbm.xml
367 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/DocTimeSlot.hbm.xml
390 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/Admin.hbm.xml
407 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/Users.hbm.xml
431 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/Invoice.hbm.xml
451 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/DocDetail.hbm.xml
468 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/Appoinment.hbm.xml
484 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : clinic/entity/RecpDetail.hbm.xml
500 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
569 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.PatientDetail -> patient_detail
582 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.PatientVisit -> patient_visit
584 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.DocTimeSlot -> doc_time_slot
586 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.Admin -> admin
586 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.Users -> users
587 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.Invoice -> invoice
588 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.DocDetail -> doc_detail
589 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.Appoinment -> appoinment
590 [AWT-EventQueue-0] INFO org.hibernate.cfg.HbmBinder - Mapping class: clinic.entity.RecpDetail -> recp_detail
596 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
602 [AWT-EventQueue-0] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
609 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
616 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
617 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
643 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/clinic_mgmt?zeroDateTimeBehavior=convertToNull
644 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
954 [AWT-EventQueue-0] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
963 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Database ->
name : MySQL
version : 5.5.34-0ubuntu0.12.04.1
major : 5
minor : 5
963 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Driver ->
name : MySQL-AB JDBC Driver
version : mysql-connector-java-5.1.23 ( Revision: ${bzr.revision-id} )
major : 5
minor : 1
964 [AWT-EventQueue-0] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
966 [AWT-EventQueue-0] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
966 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
966 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
966 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
966 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
967 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory
969 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
969 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
969 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
969 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
969 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
970 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
970 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
976 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
976 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
977 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
977 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
977 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
977 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
997 [AWT-EventQueue-0] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
1001 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@179e0ae
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@8dd0ad
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@7f3311
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.ClobType@f1cd74
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@f1cd74
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@e797e1
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@a43a5e
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@1f42804
1002 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@1f42804
1203 [AWT-EventQueue-0] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
Hibernate: select users0_.id as id4_, users0_.user_name as user2_4_, users0_.pwd as pwd4_, users0_.user_type as user4_4_ from clinic_mgmt.users users0_ where (users0_.pwd='admin' )
clinic.entity.Users@12dc62
BUILD SUCCESSFUL (total time: 5 seconds)
答案 0 :(得分:0)
尝试在提取查询中使用此功能。
String hql = "FROM Users U WHERE U.pwd=:pwd";
Query query = session.createQuery(hql);
query.setParameter("pwd","admin");
List<User> list = query.list();
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getProperty1());
System.out.println(list.get(i).getProperty1());
....
....
System.out.println(list.get(i).getPropertyN());
}
getProperty1()
---属性名称,如id,name getters