Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query not returning any data..

 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Criteria criteria = session.createCriteria(SearchA.class); is not returning any data, but i have 10000 records+ in the table..
Please let me know, whats the problem..

Code Blocks..


Database Bean:

public class SearchA {

String CatalogProducts_Item_GUID = "";

String CatalogProducts_Product_Name = "";

String CatalogProducts_Product_Description = "";

public String getCatalogProducts_Item_GUID() {
return CatalogProducts_Item_GUID;
}

public void setCatalogProducts_Item_GUID(String catalogProducts_Item_GUID) {
CatalogProducts_Item_GUID = catalogProducts_Item_GUID;
}

public String getCatalogProducts_Product_Description() {
return CatalogProducts_Product_Description;
}

public void setCatalogProducts_Product_Description(
String catalogProducts_Product_Description) {
CatalogProducts_Product_Description = catalogProducts_Product_Description;
}

public String getCatalogProducts_Product_Name() {
return CatalogProducts_Product_Name;
}

public void setCatalogProducts_Product_Name(
String catalogProducts_Product_Name) {
CatalogProducts_Product_Name = catalogProducts_Product_Name;
}
}

HQL Code :

Session session = null;
try {
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(SearchA.class);
System.out.println("******************************* \n" +
criteria.toString());
System.out.println("*******************************");
List list = criteria.list();
System.out.println("List Size -- "+list.size());
for (int i = 0; i < list.size(); i++) {
SearchA insu = (SearchA) list.get(i);
System.out.println(" HELLO " + insu.getCatalogProducts_Item_GUID()+ " -- "
+ insu.getCatalogProducts_Product_Name()+ " -- "
+ insu.getCatalogProducts_Product_Description()+ " -- ");
}
} catch (Exception e) {
System.out.println("Error " + e);
e.printStackTrace();
}

hbm.xml file:
<?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.test.SearchA" table="CatalogProducts">
<id name="CatalogProducts_Item_GUID" column="CatalogProducts_Item_GUID">
<generator class="native"/>
</id>

<property name="CatalogProducts_Product_Description"/>
<property name="CatalogProducts_Product_Name"/>
</class>
</hibernate-mapping>

Thanks in Advance..
/Shridhar..
 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Output of the above Code ::

*******************************
CriteriaImpl(com.test.SearchA:this[][])
*******************************
Hibernate: select this_.CatalogProducts_Item_GUID as CatalogP1_0_, this_.CatalogProducts_Product_Description as CatalogP2_0_0_, this_.CatalogProducts_Product_Name as CatalogP3_0_0_ from CatalogProducts this_
List Size -- 0

Thanks,
/Shridhar..
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what was the output when you fired following query in database?

select this_.CatalogProducts_Item_GUID as CatalogP1_0_, this_.CatalogProducts_Product_Description as CatalogP2_0_0_, this_.CatalogProducts_Product_Name as CatalogP3_0_0_ from CatalogProducts this_


-P
 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for reply.. It works, i added dbo.<Table_Name>..

What is is MS SQL's bigint(8) equivalent in java, also Identity is "Yes"..
Is the following hbm.xml correct??

<hibernate-mapping>
<class name="com.test.SearchA" table="dbo.CatalogProducts">
<id name="Slno" column="Slno">
<generator class="native"/>
</id>
<property name="CatalogProducts_Item_GUID"/>
<property name="CatalogProducts_Product_Description"/>
<property name="CatalogProducts_Product_Name"/>
</class>
</hibernate-mapping>


I am getting following Exception..

Caused by: java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Unhandled data type: TDS_INT8

Thanks,
Shridhar..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is is MS SQL's bigint(8) equivalent in java

A bigint can hold integer values in the range -2^63 -> 2^63-1 so it should be a Long.
 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If the DB field is having Identity is "Yes", Do i need to specify anything extra in hbm.xml file or the below is correct..


<hibernate-mapping>
<class name="com.test.SearchA" table="dbo.CatalogProducts">
<id name="Slno" column="Slno">
<generator class="native"/>
</id>
<property name="CatalogProducts_Item_GUID"/>
<property name="CatalogProducts_Product_Description"/>
<property name="CatalogProducts_Product_Name"/>
</class>
</hibernate-mapping>


Thanks,
/Shridhar..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks OK. Does it work?
 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No, Its not working.. I am getting the following message..

Thanks,
/Shridhar..


****************************************************************************

Hibernate: select this_.Slno as Slno0_, this_.CatalogProducts_Item_GUID as CatalogP2_0_0_, this_.CatalogProducts_Product_Description as CatalogP3_0_0_, this_.CatalogProducts_Product_Name as CatalogP4_0_0_ from dbo.CatalogProducts this_ where this_.CatalogProducts_Product_Name like ?
Error org.hibernate.exception.GenericJDBCException: could not execute query
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1246)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
at com.test.SearchMain.main(SearchMain.java:50)
Caused by: java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Unhandled data type: TDS_INT8
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processColMetaData(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 5 more
****************************************************************************
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[Microsoft][SQLServer JDBC Driver]

Hmmm. There was a bug in a beta version of this driver that was something like this. No idea if Microsoft ever fixed it. You might want to change your driver to use the current MS driver (since it looks like you are using the old one). Than might fix it.

Hibernate doesn't support MS's own driver, largely due to it being rubbish. I haven't checked whether they have changed this stance since MS recently released their new driver. You could change to use jTDS, which might fix the issue.
 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks, It works.
I changed it to "sun.jdbc.odbc.JdbcOdbcDriver"

/Shridhar..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't use the JDBC-ODBC bridge, since its not really recommended by Sun, let alone Hibernate. Use jTDS or the new version of the Microsoft JDBC Driver.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic