配置文件:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.connection.url">jdbc:mysql://172.16.100.36:3310/blackbox</property> <property name="hibernate.connection.username">blackboxadmin</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.search.autoregister_listeners">false</property> <property name="hibernate.show_sql">true</property> <mapping resource="blahblah"/> <mapping resource="blahblah"/> <mapping resource="blahblah"/> </session-factory> </hibernate-configuration>
其中如果不指定jndi,<session-factory>不能配置name,否则会报异常Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
。即使<session-factory name="">也不行。
如果url配置的是<property name="hibernate.connection.url">jdbc:mysql://172.16.100.36:3310/blackbox</property>
则hibernate.schema就不用配置了,否则hql语句的结构会变成XXX from blackbox.blackbox.XXX