This blog is dedicated to all Sri Lankan Java Students. You can use this blog to discuss whatever question you have related to Java. I might be able to answer your questions. Or some of you also can answer the questions If you like.
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.
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.
9 comments:
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
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());
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
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.
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
First learn hibernate separately. Then integrate with maven or whatever.
This is good
http://www.roseindia.net/hibernate/index.shtml
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..
:-)
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
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
Post a Comment