首先明确一点,persistence.xml应该放在classpath中META-INF目录下.
<?xml version="1.0"?>
<persistence>
<!--此xml文件可以包含多个persistence-unit,-->
<!--这个节点定义的内容,正是Annotation @persistenceContext 所引用的,-->
<!--也就是EntityManager所读取的 -->
<persistence-unit name="simple">
<!--可选:事务处理方式(JTA/RESOUREC_LOCAL)-->
<transaction-type>JTA</transaction>
<!--可选-->
<jta-data-source>java:/MySQLDS</jta-data-source>
<!--可选:如果你的ENTITY类都打成jar包了,可以以这种方式引进项目-->
<jar-file>../lib/entities.jar</jar-file>
<!--定义了persistence provide 厂商提供的特有属性-->
<properties>
<property name="org.hibernate.hbm2ddl">update</property>
</properties>
</persistence-unit>
</persistence>
同事,如果你不喜欢用Annotation的方式处理ORM,还可以在MATE-INF的包里提供一个ORM.xml文件,加以处理
web项目中url rewright的功能是一个很常见得功能,实现的方式多种多http://ohacker.com/wp-admin/post-new.php样,最常见的莫过于在web服务器中设置,例如在Apache中设置。而如果你使用Java开发,那么还有个更多的方案供你选择如使用url rewrite filter ,而如果你是使用resin(版本需要>3.1)作为你的application server,那么你还可以使用resin自带的url 重写功能。
首先,你必须使用resin-web.xml代替常规的web.xml作为你的项目部署描述文件,其次,你需要在描述文件中指定一个url重写的配置文件。再在这个文件中配置。
resin-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://caucho.com/ns/resin"
xmlns:resin="http://caucho.com/ns/resin/core">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<rewrite-dispatch>
<import path='WEB-INF/rewrite.xml'/>
</rewrite-dispatch>
</web-app>
rewrite.xml
<rewrite-dispatch xmlns="http://caucho.com/ns/resin"
xmlns:resin="http://caucho.com/ns/resin/core">
<redirect regexp="^/tst" target="https://ohacker.com/tst">
<when secure="false" />
</redirect>
</rewrite-dispatch>