Dear Sirs et Madames,
I am trying to experiment with
polymorphism in hibernate and have read somewhere that it is possible to query for subtypes of a class even if the subclass itself is not mapped (Hibernate in Action page 252). However when I try it, I do not get the desired result. Here is the superclass:
The subclass:
DAO class:
When I run main, I get the following output:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
compile-single:
run-main:
Jun 23, 2009 3:00:24 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
Jun 23, 2009 3:00:24 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Jun 23, 2009 3:00:24 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Jun 23, 2009 3:00:24 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Jun 23, 2009 3:00:24 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Jun 23, 2009 3:00:25 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Jun 23, 2009 3:00:25 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Jun 23, 2009 3:00:25 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/UserPrivileges.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/Privilege.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/Enumerator.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/UserType.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/User.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/Location.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : org/openhrs/common/LocationType.hbm.xml
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.UserPrivilege -> user_privileges
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.Privilege -> privilege
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.Enumerator -> enumerator
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.UserType -> user_type
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.User -> users
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.Location -> locations
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.openhrs.entities.LocationType -> location_types
Jun 23, 2009 3:00:26 PM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
Jun 23, 2009 3:00:26 PM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARNING: composite-id class does not override equals(): org.openhrs.entities.UserPrivilege
Jun 23, 2009 3:00:26 PM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARNING: composite-id class does not override hashCode(): org.openhrs.entities.UserPrivilege
Jun 23, 2009 3:00:26 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Jun 23, 2009 3:00:26 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Jun 23, 2009 3:00:26 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Jun 23, 2009 3:00:26 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL:
jdbc:mysql://localhost:3306/OpenHRS
Jun 23, 2009 3:00:26 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.67-community-nt
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
Jun 23, 2009 3:00:29 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Jun 23, 2009 3:00:29 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Jun 23, 2009 3:00:29 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Jun 23, 2009 3:00:29 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Jun 23, 2009 3:00:29 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Jun 23, 2009 3:00:29 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Jun 23, 2009 3:00:29 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Jun 23, 2009 3:00:30 PM org.hibernate.hql.QuerySplitter concreteQueries
WARNING: no persistent classes found for query class: from org.openhrs.entities.Region
BUILD SUCCESSFUL (total time: 12 seconds)
Why is it insisting it cannot find the persisted class when the book says the subclass does not have to be persisted as long as the superclass is?
Any help greatly appreciated. Thanks