1.关于Hibernate异常:
org.hibernate.service.jndi.JndiException: Error parsing JNDI name 刚接触Hibernate,调试一个简单的程序报告异常: org.hibernate.service.jndi.JndiException: Error parsing JNDI name去掉hibernate.cfg.xml
<session-factory name="sessionFactory">
中的name属性,异常解除。 没有明白是什么原因。
2.JDBC for SQL Server的连接描述:
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property><property name="hibernate.connection.url">jdbc:sqlserver://xxh/xsql2008;DatabaseName=yourdatabase;SelectMethod=cursor</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> 注意driver和url的描述
3.表映射
可以放在hibernate.cfg.xml中: <mapping resource="Person.hbm.xml"/> 也可以在代码中动态指定: Configuration cfg = new Configuration().addResource("Person.hbm.xml").configure();4.Hibernate4中的一点变化:
serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
buildSessionFactory函数新的变化。