• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i m new to hibernate

 
suren kumar
Greenhorn
Posts: 5
Hibernate Java Netbeans IDE
  • 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
 
ntumba lobo
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 Java Netbeans IDE
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic