[英]Error with persistence using EclipseLink and UCanAccess
I am trying to develop an app for exercise reasons. 我正在努力开发一个应用程序,因为运动的原因。 I am using MSAccess 2010 as the database with UCanAccess (3.06) as the driver and the EclipseLink 2.1 as the entity framework. 我使用MSAccess 2010作为数据库,UCanAccess(3.06)作为驱动程序,EclipseLink 2.1作为实体框架。
I am stuck in adding new records to the database. 我被困在向数据库添加新记录。 Here the error code: 这里的错误代码:
Internal Exception: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 user lacks privilege or object not found: IDENTITY_VAL_LOCAL
Error Code: -5501
Call: SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1
Query: ValueReadQuery(name="SEQ_GEN_IDENTITY" sql="SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1")
It seems to me that the autogenerate of the id fails. 在我看来,id的自动生成失败了。 The entity class was generated vie Netbeans and looks like this: 实体类是通过Netbeans生成的,如下所示:
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
By default, EclipseLink tries to automatically detect the underlying database and generate SQL statements using the appropriate SQL dialect. 默认情况下,EclipseLink尝试使用适当的SQL方言自动检测基础数据库并生成SQL语句。 That apparently isn't working for you because the SQL statement to retrieve the last created identity value is not recognized by UCanAccess . 这显然不适合您,因为UCanAccess无法识别用于检索上次创建的标识值的SQL语句。
You could try adding a target-database directive to your EclipseLink configuration specifying SQLServer
in an attempt to get a working SQL statement ( SELECT @@IDENTITY
) to retrieve the last created ID value. 您可以尝试向EclipseLink配置添加target-database指令,指定SQLServer
以尝试获取有效的SQL语句( SELECT @@IDENTITY
)以检索上次创建的ID值。 However, bear in mind that there are significant differences between T-SQL and Access SQL so you will probably continue to encounter other compatibility issues between EclipseLink and UCanAccess. 但是,请记住,T-SQL和Access SQL之间存在显着差异,因此您可能会继续遇到EclipseLink和UCanAccess之间的其他兼容性问题。
before knowing above answer i was also facing same problem for inserting new record in access Database , Thanks to Mr. Gord Thompson to give a great Solution for me , and it is working too. 在了解上述答案之前,我也面临着在访问数据库中插入新记录的同样问题,感谢Gord Thompson先生为我提供了一个很好的解决方案,而且它也在起作用。
i have just added one line in my persistence.xml file.. 我刚刚在persistence.xml文件中添加了一行代码。
property name="eclipselink.target-database" value="HSQL" property name =“eclipselink.target-database”value =“HSQL”
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="OnePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>design_frames.One</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:ucanaccess://C:\One\One.accdb"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.driver" value="net.ucanaccess.jdbc.UcanaccessDriver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="eclipselink.target-database" value="HSQL"/>
</properties>
</persistence-unit>
</persistence>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.