Monday, February 11, 2008

Hibernate

Post your Hibernate questions here.

9 comments:

Unknown 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.

Thnkx,

Dasun

Nishantha said...

Step1

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();
System.out.println(t.getColumn(0).getName());

Unknown 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();
System.out.println(tt.getColumn(0).getName());

and my etity class anotations are

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

can u tell me where is the problem
thnkx a lot

DASUN

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.

Bugi said...

Sir,

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.

thanx,
Bhagya

Nishantha said...

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

This is good
http://www.roseindia.net/hibernate/index.shtml

Mifraz Marzoon said...

bhagya,

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

http://www.lulu.com/items/volume_62/1087000/1087191/3/print/Hibernate-Spring-Maven-Eclipse-Tutorial.pdf

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

:-)

Bugi said...

Sir,

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

Bugi 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

Bhagya