Code:
Hibernate : 2.1.6
mysql : 3.23.56
Tomcat :5.16
The hibernate.cfg.xml is following:
Code:
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<mapping resource="Trade.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The mapping file:
Code:
<hibernate-mapping>
<class name="lyo.test.bean.Trade" table="tradetest">
<id name="trade_id" column="trade_id" type="int">
<generator class="native"/>
</id>
<property name="trade_name" column="trade_name"/>
<property name="trade_desc" column="trade_desc"/>
</class>
</hibernate-mapping>
I have a java helper class:
Code:
public class HibernateUtil {
//private static Logger log = LogFactory.getLog(HibernateUtil.class);
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
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();
}
}
hibernate.properties File is:
Code:
#hibernate.connection.driver_class org.gjt.mm.mysql.Driver
#hibernate.connection.url jdbc:mysql://localhost:3306/poweracl
#hibernate.connection.username lyo
#hibernate.connection.password qijiashe
I use it in this way:
Code:
Session s=HibernateUtil.currentSession();
Transaction t=s.beginTransaction();
List list=s.find("from Trade as trade");
t.commit();
HibernateUtil.closeSession();
return list;
Everytime I run it ,Tomcat console will output:
Code:
08:20:37,281 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLoo
kup configured (in JTA environment, use of process level read-write cache is not
recommended)
08:20:37,484 INFO SettingsFactory:103 - Use scrollable result sets: true
08:20:37,484 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): false
08:20:37,484 INFO SettingsFactory:109 - Optimize cache for minimal puts: false
08:20:37,484 INFO SettingsFactory:115 - echoing all SQL to stdout
08:20:37,484 INFO SettingsFactory:118 - Query language substitutions: {no='N',
true=1, yes='Y', false=0}
.............................................................................................
........................................................................
....................................................................
08:20:37,515 INFO Configuration:1116 - instantiating and configuring caches
08:20:37,734 INFO SessionFactoryImpl:118 - building session factory
08:20:38,343 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI,
no JNDI name configured
08:20:38,359 INFO UpdateTimestampsCache:35 - starting update timestamps cache a
t region: net.sf.hibernate.cache.UpdateTimestampsCache
08:20:38,359 INFO StandardQueryCache:41 - starting query cache at region: net.s
f.hibernate.cache.StandardQueryCache
Hibernate: select trade0_.trade_id as trade_id, trade0_.trade_name as trade_name
, trade0_.trade_desc as trade_desc from tradetest trade0_
Is there any problem ?