Hi david,
iam able to get the table details from this query ,
but problem is in mapping class only.
select * from all-TAbles where owner='SCHEMA_NAME';
In this list iam not geting primary key to mention in *.hbm.xml file where i have to give tablename and id's.
IAm tracing the problem here:
Exception in thread "main" org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query. [select * from all_tables where owner='schema_name']
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:169)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:140)
at com.wdcs.dbcommon.test.createQuery(test.java:105)
at com.wdcs.dbcommon.test.main(test.java:138)
I am sending u the code also.
Code:
Session session=sessionFactory.openSession();
// Query qry=session.createQuery(arg);
String sql = "select * from all_tables where owner='WDCSMAIN'";
Query q = session.createSQLQuery( sql );
// System.out.println("Query ::"+q.toString()+"::"+q.iterate());
List names = q.list();
if ( names != null && !(names.isEmpty()) ) {
int length = names.size();
for ( int i=0; i<length; i++ ) {
Object object = names.get( i );
if ( object instanceof Object[] ) {
Object[] cols = (Object[]) object;
for ( int col=0; col<cols.length; col++ ) {
System.out.print( cols[ col ] + " | ");
}
}
}
}
Iam able to connect with database only with other mapping class but for table name i cant even map..
Please help me how to solve this..
the table name mapping xml file is as folows:
Code:
<?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>
<class name="com.wdcs.dbcommon.Tablename" table="tbname">
<property name="table_name"/>
</class>
</hibernate-mapping>
If i add this mapping class to config object then the error will be different as follows:
Initial SessionFactory creation failed.org.hibernate.MappingException: Error reading resource: com/wdcs/dbcommon/Tablename.hbm.xml
org.hibernate.MappingException: Error reading resource: com/wdcs/dbcommon/Tablename.hbm.xml
at org.hibernate.cfg.Configuration.addClass(Configuration.java:471)
at com.wdcs.dbcommon.test.getconnection(test.java:51)
at com.wdcs.dbcommon.test.main(test.java:136)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:399)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:468)
... 2 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398)
... 3 more
Exception in thread "main" java.lang.NullPointerException
Please tel me how to access enity object withour a primary key..
Hope uunderstand my problem.
waiting for your help.thanks ina dvance
Regards,
chintu