-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How select * from tab works in hibernate.
PostPosted: Thu May 11, 2006 2:03 am 
Newbie

Joined: Wed May 10, 2006 5:34 am
Posts: 7
Hi all,
i want thelist of tables in datbase,
iam using oracle database, sql query "select * from tab";
list the table names same kind i need to do with hibernate.. plz any one help me to solve it.
Regards,
Chintu


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 5:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Use a native SQL query (or the JDBC connection). See manual for examples.


Top
 Profile  
 
 Post subject: How select * from tab works in hibernate.
PostPosted: Wed May 17, 2006 1:54 am 
Newbie

Joined: Wed May 10, 2006 5:34 am
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.