您的位置:程序门 -> java -> intellij idea



struts+hibernate+spring,jdbc连接池问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


struts+hibernate+spring,jdbc连接池问题
发表于:2007-04-25 22:59:18 楼主
我在写整合案例时,hibernate.cfg.xml是通过spring配置的,但是hibernate.hbm.xml总是映射不到我在datasource   tools里配置的数据库,
table和column要出错,提示不可用properties,我进入setting里的project   structure里的hibernate里想配置session   factory   但是里面是空的,无法选择datasource,我看7.01m1的demo上他演示这一步的时候session   factory里有个info的工厂,他是怎么弄出来的啊,我研究半天都弄不出来,
还有就是spring的applicationcontext.xml里的 <datasource> 下的jndi连接数据源连到的是哪里啊,在jboss或tomcat里还要配什么不,我看书上说要写个
postgre-jdbc.xml(我用的数据库是postgresql),但我不知道是要我放到web-inf下还是放到jboss里的什么地方,
最好给我讲讲通过jndi连接池连接数据库到底怎么弄,还有原理是什么,谢谢
我可能叙述的不太清楚,不过大家要是看不太懂就回贴问我,最重要就是要解决问题,望高手指点
发表于:2007-05-19 22:40:151楼 得分:0
hibernate.cfg.xml <?xml   version= "1.0 "   encoding= "gb2312 "   ?> <!doctype   hibernate-configuration   public   "-//hibernate/hibernate   configuration   dtd//en "   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd "> <hibernate-configuration>     <session-factory>         <property   name= "hibernate.connection.driver_class "> org.gjt.mm.mysql.driver </property>             <property   name= "hibernate.connection.url "> jdbc:mysql://localhost/struts?useunicode=true&characterencoding=latin1 </property>         <property   name= "hibernate.connection.username "> root </property>         <property   name= "hibernate.connection.password "> 123456 </property>                 <property   name= "show_sql "> true </property>         <property   name= "dialect "> net.sf.hibernate.dialect.mysqldialect </property>         <mapping   resource= "hb/user.hbm.xml "   />     </session-factory> </hibernate-configuration> hibernateutil.javapackage   hb;import   net.sf.hibernate.*;import   net.sf.hibernate.cfg.*;public   class   hibernateutil   {         private   static   final   sessionfactory   sessionfactory;         static   {                 try   {                         sessionfactory   =   new   configuration().configure().buildsessionfactory();                 }   catch   (hibernateexception   ex)   {                         throw   new   runtimeexception( "exception   building   sessionfactory:   "   +   ex.getmessage(),   ex);                 }         }         public   static   final   threadlocal   session   =   new   threadlocal();         public   static   session   currentsession()   throws   hibernateexception   {               //       session   s;                 session   s   =   (session)   session.get();                 //   open   a   new   session,   if   this   thread   has   none   yet                 if   (s   ==   null)   {                         s   =   sessionfactory.opensession();                       session.set(s);                 }                 return   s;         }         public   static   void   closesession()   throws   hibernateexception   {                 session   s   =   (session)   session.get();                 session.set(null);                 if   (s   !=   null)                         s.close();         }}
发表于:2007-08-01 14:18:142楼 得分:0
ok!!!!!!!!!!!!!!!!


快速检索

最新资讯
热门点击