Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
I tried in two ways
[u][b]I[/b][/u]
[b]Hibernate version:[/b]
Hibernate3 beta 3
[b]Mapping documents:[/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="testApp">
<class name="Department" table="dept" lazy="true">
<id name="deptNo" column="deptno" type="int">
<generator class="native"/>
</id>
<property name="deptName" column="deptname" />
<property name="deptLoc" column="deptloc" />
</class>
</hibernate-mapping>
[b]Code between sessionFactory.openSession() and session.close():[/b]
Session session = factory.openSession();
try {
Query query = session.createSQLQuery("SELECT {d.*} FROM dept
{d}","d",Department.class);
System.out.println("Query created : "+query);
List list = query.list();
System.out.println("List size : "+list.size());
Iterator iterator = list.iterator();
while(iterator.hasNext()){
System.out.println("Department name is : "+((Department)
iterator.next()).getDeptName());
}
}
catch(Exception e){
System.out.println("Exception in method " + e);
}
finally {
session.close();
}
[b]Full stack trace of any exception that occurs:[/b]
java.lang.Error: Unresolved compilation problem:
The method createSQLQuery(String) in the type Session is not applicable for the arguments (String, String, Class)
at testApp.SampleApp.getDepartmentDetailsByDept(SampleApp.java:126)
at testApp.SampleApp.main(SampleApp.java:61)
Exception in thread "main"
[b]Name and version of the database you are using:[/b]
Oracle 9
[b]The generated SQL (show_sql=true):[/b]
No sql generated
[b]Debug level Hibernate log excerpt:[/b]
Feb 16, 2005 10:27:28 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0 beta 3
Feb 16, 2005 10:27:28 AM org.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.order_updates=true, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=hibernate, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@192.168.210.109:1521:EIPTEST1, hibernate.connection.password=hibernate321, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
Feb 16, 2005 10:27:28 AM org.hibernate.cfg.Environment <clinit>
INFO: using java.io streams to persist binary types
Feb 16, 2005 10:27:28 AM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Feb 16, 2005 10:27:28 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Feb 16, 2005 10:27:28 AM org.hibernate.cfg.Configuration addClass
INFO: Mapping resource: testApp/Department.hbm.xml
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.HbmBinder bindRootClass
INFO: Mapping class: testApp.Department -> dept
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Feb 16, 2005 10:27:29 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle9Dialect
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 1
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: enabled
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory
Feb 16, 2005 10:27:29 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {no='N', true=1, yes='Y', false=0}
Feb 16, 2005 10:27:29 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Feb 16, 2005 10:27:29 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
Feb 16, 2005 10:27:29 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Feb 16, 2005 10:27:29 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@192.168.210.109:1521:EIPTEST1
Feb 16, 2005 10:27:29 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=hibernate, password=****}
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: enabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Feb 16, 2005 10:27:30 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Feb 16, 2005 10:27:30 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.HashtableCacheProvider
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Cache region prefix: hibernate.test
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Feb 16, 2005 10:27:30 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Feb 16, 2005 10:27:30 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Feb 16, 2005 10:27:30 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Feb 16, 2005 10:27:30 AM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
java.lang.Error: Unresolved compilation problem:
The method createSQLQuery(String) in the type Session is not applicable for the arguments (String, String, Class)
at testApp.SampleApp.getDepartmentDetailsByDept(SampleApp.java:126)
at testApp.SampleApp.main(SampleApp.java:61)
Exception in thread "main"
[u][b]II[/b][/u]
[b]Hibernate version:[/b]
Hibernate3 beta 3
[b]Mapping documents:[/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="testApp">
<class name="Department" table="dept" lazy="true">
<id name="deptNo" column="deptno" type="int">
<generator class="native"/>
</id>
<property name="deptName" column="deptname" />
<property name="deptLoc" column="deptloc" />
</class>
</hibernate-mapping>
[b]Code between sessionFactory.openSession() and session.close():[/b]
Session session = factory.openSession();
try {
Query query = session.createSQLQuery("SELECT * FROM dept");
System.out.println("Query created : "+query);
List list = query.list();
System.out.println("List size : "+list.size());
Iterator iterator = list.iterator();
while(iterator.hasNext()){
System.out.println("Department name is : "+((Department)
iterator.next()).getDeptName());
}
}
catch(Exception e){
System.out.println("Exception in method " + e);
}
finally {
session.close();
}
[b]Full stack trace of any exception that occurs:[/b]
List size : 12
Exception in method java.lang.ClassCastException
[b]Name and version of the database you are using:[/b]
Oracle 9
[b]The generated SQL (show_sql=true):[/b]
Query I/P : SELECT * FROM dept
Query O/P : SELECT * FROM dept
[b]Debug level Hibernate log excerpt:[/b]
Feb 16, 2005 10:38:32 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0 beta 3
Feb 16, 2005 10:38:32 AM org.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.order_updates=true, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=hibernate, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@192.168.210.109:1521:EIPTEST1, hibernate.connection.password=hibernate321, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
Feb 16, 2005 10:38:32 AM org.hibernate.cfg.Environment <clinit>
INFO: using java.io streams to persist binary types
Feb 16, 2005 10:38:32 AM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Feb 16, 2005 10:38:32 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Feb 16, 2005 10:38:32 AM org.hibernate.cfg.Configuration addClass
INFO: Mapping resource: testApp/Department.hbm.xml
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.HbmBinder bindRootClass
INFO: Mapping class: testApp.Department -> dept
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Feb 16, 2005 10:38:33 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle9Dialect
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 1
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: enabled
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory
Feb 16, 2005 10:38:33 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {no='N', true=1, yes='Y', false=0}
Feb 16, 2005 10:38:33 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Feb 16, 2005 10:38:33 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
Feb 16, 2005 10:38:33 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Feb 16, 2005 10:38:33 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@192.168.210.109:1521:EIPTEST1
Feb 16, 2005 10:38:33 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=hibernate, password=****}
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: enabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Feb 16, 2005 10:38:34 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Feb 16, 2005 10:38:34 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.HashtableCacheProvider
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Cache region prefix: hibernate.test
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Feb 16, 2005 10:38:34 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Feb 16, 2005 10:38:34 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Feb 16, 2005 10:38:34 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Feb 16, 2005 10:38:34 AM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
Query created : SQLQueryImpl(SELECT * FROM dept)
Query I/P : SELECT * FROM dept
Query O/P : SELECT * FROM dept
SQLCustomQuery : 1 SELECT * FROM dept
SQLCustomQuery : 2 SELECT * FROM dept
SQLCustomQuery : 3 SELECT * FROM dept
SQLCustomQuery : 4 SELECT * FROM dept
SQLCustomQuery : 5 SELECT * FROM dept
SQLCustomQuery : 6 SELECT * FROM dept
SQLCustomQuery : End SELECT * FROM dept
List size : 12
Exception in method java.lang.ClassCastException
In the first case it is not creating the query itself. In the second case its creating the query but am not able to typecast it to Department.