• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

i m new to hibernate

 
Greenhorn
Posts: 5
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to count the number of rows and column in hibernate.
how to compare the values of each field in one table with each field in another table
 
Ranch Hand
Posts: 180
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use HQL which is very similar to SQL and do "select count(*) from MyPersistentClass" .

You can also use the Criteria API and do something like
Criteria criteria = session.createCriteria(MyPersistentClass.class);
criteria.setProjection(Projections.rowCount());
Integer rowCount = ((Integer)criteria.list().get(0)).intValue();
 
suren kumar
Greenhorn
Posts: 5
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...

i got the row count..

and i need the column count of the table..?
thanks
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean the number of columns in a particular table ?
If that's the case and this is your DB you should know this information upfront no need to determine this at runtime.

Anyway you can get this information via jdbc metadata like this

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();

But in Hibernate really I dont know. This is a static known information usually.
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just thought of it, actually you can use the Hibernate sessionFactory to get the database metadata.
You have methods like getAllClassMetadata() or getClassMetadata(Class entityClass)

Have a look to java doc to see all that is available to you
 
    Bookmark Topic Watch Topic
  • New Topic