Monday, February 11, 2008


Post your Hibernate questions here.


Laksiri said...

Hi All,

Is there any way to get Hibernate Mapping Data without rebuilding Sessionfactory. Actually i want to get the information about tables and columns of relaveant pesistant class.



Nishantha said...


Create a Configuration object.

Configuration cfg = new Configuration().configure(); //if u have the hibernate.cfg.xml in classpath, otherwise u have to pass the filepath.

Step 2
Get the persistent class for the required class

PersistentClass pc = cfg.getClassMapping("my.Department");

Step 3
Get the table
Table t =pc.getTable();

Laksiri said...

thank u very much sir; this is very helpful to us.we ll give maximum support.

I have tried this but it gives null point exception at cc.getTabele()
here is my code..

Configuration c = new Configuration().configure(new File("E:\\software\\eclipse\\SDB\\SDBServer\\ejbModule\\business\\hbm\\hibernate.cfg.xml"));

PersistentClass cc=c.getClassMapping("COMP");

Table tt= cc.getTable();

and my etity class anotations are

@Table(name = "COMP", catalog = "SDB")
public class Comp implements,ECSObject {...}

can u tell me where is the problem
thnkx a lot


Nishantha said...

I think you have used annotations for specifying the table.

So far I have not used annotations to specify the mapping details. Still we are specifying the mapping in the hbm file. I think what is happening is you r trying to get mapping details from hbm (thru cfg) which is not there. Since it is in the code. so you can't find the mapping in the hbm c.getClassMapping("COMP") will return null. Just try defining ur entity in a hbm and see.

Bhagya said...


Will u tell me the most suitable URLs or tutorials to learn Hibernate from the beginning.It's better if Hibernate with Eclipse and Maven.


Nishantha said...

First learn hibernate separately. Then integrate with maven or whatever.

This is good

Mifraz Marzoon said...


This is a nice tutorial on eclipse,spring,hibernate,maven. will be usefull for u

but the best way is to learn hibernate separately like your sir said..


Bhagya said...


Thank you very much for the Hibernate link.I started to learn hibernate,separately from that.

I thought to learn with maven,because I have to work with maven.But i got the best way to gain good knowledge about hibernate.

thanx a lot


Bhagya said...

Mifraz Aiya,

Thank you very much for the Hibernate link.It will be very helpful for me later,to progress my knowledge with maven and eclipse.

thanx a lot