我嘗試使用帶插件gorm-jpa 0.7.1的Grails 1.3.7來使用EclipseLink 2.2.0作爲持久性提供程序來啓用JPA持久性。在EclipseLink 2.2.0中使用Grails 1.3.7 JPA Provider
當運行應用程序,並單擊JPA註解實體離開的EclipseLink的JPQLParser控制器我得到一個「UnwantedTokenException」上:
Executing action [list] of controller [model.PersonController] caused exception:
An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [select person from model.Person as person ], line 1, column 24: syntax error at [.].
Internal Exception: UnwantedTokenException(found=., expected 80);
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:587)
[...]
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.parse(JPQLParser.java:134)
看來的EclipseLink與在「模型中的點有問題。人」。
如何解決這個問題?
重現該問題設置一個Grails項目如下:
grails create-app GrailsJPA
cd GrailsJPA
grails uninstall-plugin hibernate
grails install-plugin gorm-jpa
grails create-domain-class model.Person
編輯 「的grails-app \域\型號\ Person.groovy」 如下:
package model
import javax.persistence.*;
@Entity
class Person {
@Id
@GeneratedValue
long id;
@Basic
long version;
@Basic
String firstName
@Basic
String lastName
static constraints = {
firstName(nullable:true)
lastName(nullable:true)
}
}
生成控制器和視圖爲所定義的實體:
grails generate-controller model.Person
grails generate-view model.Person
編輯 「的grails-app \ CONF \彈簧\ resources.groovy」 如下:
beans = {
entityManagerFactory(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) {
beanClassLoader = ref("classLoader")
dataSource = ref("dataSource")
loadTimeWeaver = new org.springframework.instrument.classloading.SimpleLoadTimeWeaver()
}
transactionManager(org.springframework.orm.jpa.JpaTransactionManager) {
entityManagerFactory = entityManagerFactory
}
}
創建一個文件 「web應用程序\ WEB-INF \類\ META-INF \ persistence.xml中」 具體如下:http://www.eclipse.org/eclipselink/downloads/2.2.0和提取
<?xml version="1.0" encoding="UTF-8"?>
<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="manager" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>model.Person</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
下載的EclipseLink 2.2.0安裝ZIP 「eclipselink.jar」 從 「的EclipseLink \ jlib \」 在ZIP到Grails項目目錄:
lib\eclipselink.jar
現在運行Grails應用程序:
grails run-app
瀏覽
http://localhost:8080/GrailsJPA
現在點擊控制器 「model.PersonController」 重現上面的異常。
關於如何解決此問題的任何想法?