我也初学hibernate,但是我写的程序没有这个问题,up&。
解决方案 »
- jstl问题 在线等
- form中的值获取不到
- request.getRequestDispatcher() 的地址可不可以带参数?
- 就三个文件,但是出现乱码,郁闷!!!!!!!
- 关于ibatis版的jpetstore 5.0的一个问题,求助
- 请问现在在公司做Web开发的师兄师姐们
- 关于getHibernateTemplate().update()的问题!
- 用getString()从mysql中取出时间为2005-05-15 06:29:50.0
- jsp页面java打印问题 菜鸟急寻高手 SOS
- 编译时出现找不到java.servlet.*;了
- [求助]一个关于URL编解、码的问题!!!!
- 急问:mysql出现的问题
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"><hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="hibernate.connection.url">
jdbc:mysql://192.168.1.90/db_congress?useUnicode=true&characterEncoding=gbk
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password" />
<!-- property name="hibernate.connection.pool_size"></property -->
<!-- dialect for MySQL -->
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</property>
<mapping resource="com/netec/congress/model/TbSysVocation.hbm" />
<mapping resource="com/netec/congress/model/TbDeputyBaseinfo.hbm" />
<mapping resource="com/netec/congress/model/TbSysMeetingtype.hbm" />
<mapping resource="com/netec/congress/model/TbSysVotezone.hbm" />
<mapping resource="com/netec/congress/model/TbMeetingdoc.hbm" />
<mapping resource="com/netec/congress/model/TbSysClan.hbm" />
<mapping resource="com/netec/congress/model/TbSysDegree.hbm" />
<mapping resource="com/netec/congress/model/TbMeeting.hbm" />
<mapping resource="com/netec/congress/model/TbAgendaitem.hbm" />
<mapping resource="com/netec/congress/model/TbDeputation.hbm" />
<mapping resource="com/netec/congress/model/TbSysNation.hbm" />
<mapping resource="com/netec/congress/model/TbSysMeetingdoctype.hbm" />
<mapping resource="com/netec/congress/model/TbSysPeriod.hbm" />
<mapping resource="com/netec/congress/model/TbDeputyExtendinfo.hbm" />
<mapping resource="com/netec/congress/model/TbSysConfig.hbm" />
<mapping resource="com/netec/congress/model/TbAuditpersonInfo.hbm" />
<mapping resource="com/netec/congress/model/TbSysAuditsort.hbm" />
</session-factory>
</hibernate-configuration>
if (null == configFileName && sessionFactoryMap.size() > 0) return;
else if (null != sessionFactoryMap.get(configFileName)) return;
else {
Configuration cfg = new Configuration();
if (null == configFileName)
cfg.configure();
else
cfg.configure(configFileName);
setSessionFactory(configFileName, cfg.buildSessionFactory());
}
} /**
* Set the session factory
*/
protected static void setSessionFactory (SessionFactory sessionFactory) {
setSessionFactory((String) null, sessionFactory);
} /**
* Set the session factory
*/
protected static void setSessionFactory (String configFileName, SessionFactory sessionFactory) {
sessionFactoryMap.put(configFileName, sessionFactory);
} /**
* Return the SessionFactory that is to be used by these DAOs. Change this
* and implement your own strategy if you, for example, want to pull the SessionFactory
* from the JNDI tree.
*/
protected SessionFactory getSessionFactory() throws HibernateException {
return getSessionFactory (getConfigurationFileName());
} private static SessionFactory getSessionFactory(String configFile) throws HibernateException {
if (sessionFactoryMap.size() == 1) return (SessionFactory) sessionFactoryMap.values().toArray()[0];
else {
SessionFactory sessionFactory = (SessionFactory) sessionFactoryMap.get(configFile);
if (null == sessionFactory)
if (null == configFile)
throw new RuntimeException("The session factory has not been initialized.");
else
throw new RuntimeException("The session factory for '" + configFile + "' has not been initialized.");
else
return sessionFactory;
}
} /**
* Return a new Session object that must be closed when the work has been completed.
* @return the active Session
*/
protected Session getSession() throws HibernateException {
return createSession();
} /**
* Return a new Session object that must be closed when the work has been completed.
* @return the active Session
*/
public static Session createSession() throws HibernateException {
return createSession(null);
} /**
* Return a new Session object that must be closed when the work has been completed.
* @param configFile the config file must match the meta attribute "config-file" in the hibernate mapping file
* @return the active Session
*/
public static Session createSession(String configFile) throws HibernateException {
java.util.Stack sessionStack = (java.util.Stack) threadedSessions.get();
Session session = null;
if (null == sessionStack) {
sessionStack = new java.util.Stack();
threadedSessions.set(sessionStack);
}
if (sessionStack.size() > 0) {
Object[] arr = (Object[]) sessionStack.peek();
String cf = (String) arr[0];
if (null == cf) {
session = (Session) arr[1];
}
else if (null != cf && null != configFile) {
if (cf.equals(configFile)) session = (Session) arr[1];
}
if (null == session) {
session = getSessionFactory(configFile).openSession();
arr = new Object[2];
arr[0] = configFile;
arr[1] = session;
sessionStack.push(arr);
}
}
else {
session = getSessionFactory(configFile).openSession();
Object[] arr = new Object[2];
arr = new Object[2];
arr[0] = configFile;
arr[1] = session;
sessionStack.push(arr);
}
return session;
}
05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment Hibernate 3.0
[05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment loaded properties from resource hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=org.hibernate.dialect.OracleDialect, hibernate.show_sql=true, hibernate.connection.datasource=jdbc/OracleDs}
[05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment using CGLIB reflection optimizer
[05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment JVM does not support Statement.getGeneratedKeys()
[05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled
[05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment using workaround for JVM bug in java.sql.Timestamp
[05-4-12 12:03:34:703 CST] 3cc2d191 Environment I org.hibernate.cfg.Environment using pre JDK 1.4 java.sql.Timestamp handling
[
还有你在初始化得到factory 是不是静态的?
如果是运行的时候慢,看年看你的session怎么了用了。是不是每次对数据库操作都要创建新的session
public void init() throws ServletException {
try {
..........................
factory = new Configuration().configure().buildSessionFactory();
System.out.println("数据库初始化成功");
} catch (HibernateException e) {
e.printStackTrace();
System.out.println("数据库初始化失败");
}
}然后在web.xml中加:
<servlet>
<servlet-name>CongressConfigInit</servlet-name>
<servlet-class>
XXX.IntializtionServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"><hibernate-configuration>
<session-factory name="foo">
<mapping resource="struts/advinfo/db/Advisor.hbm.xml"/>
<mapping resource="sys/bm/Duty.hbm.xml"/>
<mapping resource="struts/message/bo/Accessories.hbm.xml"/>
<mapping resource="struts/message/bo/Body.hbm.xml"/>
<mapping resource="struts/message/bo/Send.hbm.xml"/>
</session-factory>
</hibernate-configuration>
没有下到3。0的配置摸班