所以我在Spring WS中实现JPA和Hibernate时遇到了这个问题。
我已经正确配置了所有内容,根据教程它应该可行 - 但事实并非如此。
问题在于persistance.xml
,这就是它的外观:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistance_1_0.xsd"
version="1.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
</properties>
</persistence-unit>
</persistence>
我得到的例外:
Caused by: java.io.FileNotFoundException: class path resource [persistence_1_0.xsd] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:177)
at org.springframework.orm.jpa.PersistenceUnitReader.validateResource(PersistenceUnitReader.java:281)
at org.springframework.orm.jpa.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:108)
... 57 more
我一直在努力解决这个问题......有没有人知道我错过了什么?
答案 0 :(得分:1)
答案 1 :(得分:0)
.xsd文件的网址中有一个类型。尝试使用:http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd。调试这些类型问题的一个好方法是尝试在浏览器中点击URL,成功的请求表示有效链接。
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
</properties>
</persistence-unit>
</persistence>
确保您的项目名称不包含任何空格,也不应该包含项目的路径。这会在Hibernate实体管理器中产生错误。