我正在尝试根据运动原因开发应用程序。我使用MSAccess 2010作为数据库,UCanAccess(3.06)作为驱动程序,EclipseLink 2.1作为实体框架。
我无法在数据库中添加新记录。这里是错误代码:
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")
在我看来,id的自动生成失败了。实体类是通过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;
答案 0 :(得分:0)
默认情况下,EclipseLink会尝试自动检测基础数据库并使用适当的SQL方言生成SQL语句。这显然不适合您,因为UCanAccess无法识别用于检索上次创建的标识值的SQL语句。
您可以尝试在指定SQLServer
的EclipseLink配置中添加target-database指令,以尝试获取有效的SQL语句(SELECT @@IDENTITY
)以检索上次创建的ID值。但是,请记住,T-SQL和Access SQL之间存在显着差异,因此您可能会继续遇到EclipseLink和UCanAccess之间的其他兼容性问题。
答案 1 :(得分:0)
在知道上述答案之前我也面临在访问数据库中插入新记录的相同问题, 感谢先生。 Gord Thompson 给我一个很好的解决方案, 它也在发挥作用。
我刚在persistence.xml文件中添加了一行..
属性名称=" eclipselink.target-database"值=" 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>