- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我是 JPA 新手,刚开始使用 EclipseLink。在教程的帮助下,我开始创建我的第一个 JPA 项目,它包含一个实体(使用 JPA 工具自动创建),一个简单的主类,触发最基本的选择查询。但是,当我尝试运行主类时,我得到了 PersistenceUnit 的预部署失败异常。我正在使用 SQL Server Express 2008 并查询示例 AdventureWorks 数据库。能够连接到数据库(使用数据库开发视角)。详细的错误日志和代码片段如下:
主类
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import model.Employee;
public class Main {
public static void main(String[] args) {
EntityManager em = Persistence.createEntityManagerFactory("JPA2").createEntityManager();
List<Employee> list = em.createQuery("Select * from humanresources.Employee", Employee.class).getResultList();
for(Employee e : list)
{
System.out.println(e.getBirthDate());
}
}
}
实体
package model;
import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
@Entity
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="BusinessEntityID")
private int businessEntityID;
@Column(name="BirthDate")
private Object birthDate;
@Column(name="Gender")
private Object gender;
@Column(name="HireDate")
private Object hireDate;
@Column(name="JobTitle")
private Object jobTitle;
@Column(name="MaritalStatus");
private Object maritalStatus;
@Column(name="ModifiedDate")
private Timestamp modifiedDate;
@Column(name="NationalIDNumber")
private Object nationalIDNumber;
@Column(name="OrganizationLevel")
private short organizationLevel;
@Column(name="OrganizationNode")
private String organizationNode;
private String rowguid;
@Column(name="SickLeaveHours")
private short sickLeaveHours;
@Column(name="VacationHours")
private short vacationHours;
public Employee() {
}
public int getBusinessEntityID() {
return this.businessEntityID;
}
public void setBusinessEntityID(int businessEntityID) {
this.businessEntityID = businessEntityID;
}
public Object getBirthDate() {
return this.birthDate;
}
public void setBirthDate(Object birthDate) {
this.birthDate = birthDate;
}
public Object getGender() {
return this.gender;
}
public void setGender(Object gender) {
this.gender = gender;
}
public Object getHireDate() {
return this.hireDate;
}
public void setHireDate(Object hireDate) {
this.hireDate = hireDate;
}
public Object getJobTitle() {
return this.jobTitle;
}
public void setJobTitle(Object jobTitle) {
this.jobTitle = jobTitle;
}
public Object getMaritalStatus() {
return this.maritalStatus;
}
public void setMaritalStatus(Object maritalStatus) {
this.maritalStatus = maritalStatus;
}
public Timestamp getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Timestamp modifiedDate) {
this.modifiedDate = modifiedDate;
}
public Object getNationalIDNumber() {
return this.nationalIDNumber;
}
public void setNationalIDNumber(Object nationalIDNumber) {
this.nationalIDNumber = nationalIDNumber;
}
public short getOrganizationLevel() {
return this.organizationLevel;
}
public void setOrganizationLevel(short organizationLevel) {
this.organizationLevel = organizationLevel;
}
public String getOrganizationNode() {
return this.organizationNode;
}
public void setOrganizationNode(String organizationNode) {
this.organizationNode = organizationNode;
}
public String getRowguid() {
return this.rowguid;
}
public void setRowguid(String rowguid) {
this.rowguid = rowguid;
}
public short getSickLeaveHours() {
return this.sickLeaveHours;
}
public void setSickLeaveHours(short sickLeaveHours) {
this.sickLeaveHours = sickLeaveHours;
}
public short getVacationHours() {
return this.vacationHours;
}
public void setVacationHours(short vacationHours) {
this.vacationHours = vacationHours;
}
}
Persistence.XML(在 Meta-INF 文件夹下)
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
<persistence-unit name="JPA2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>model.Employee</class>
<properties>
<property name="eclipselink.target-database" value="SQLServer"/>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2008"/>
<property name="javax.persistence.jdbc.user" value="Username"/>
<property name="javax.persistence.jdbc.password" value="Username"/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
</properties>
</persistence-unit>
异常
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.2.v20130514- 5956486): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@1ac04e8
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JPA2] failed.
Internal Exception: Exception [EclipseLink-7155] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute [hireDate] on the entity class [class model.Employee] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPer sistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvi der.java:118)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at Main.main(Main.java:20)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JPA2] failed.
Internal Exception: Exception [EclipseLink-7155] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute [hireDate] on the entity class [class model.Employee] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenc eException(EntityManagerSetupImpl.java:1556)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImp l.java:1547)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer .java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvi der.java:108)
... 3 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JPA2] failed.
Internal Exception: Exception [EclipseLink-7155] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute [hireDate] on the entity class [class model.Employee] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManage rSetupException.java:221)
... 7 more
Caused by: Exception [EclipseLink-7155] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute [hireDate] on the entity class [class model.Employee] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
at org.eclipse.persistence.exceptions.ValidationException.invalidTypeForSerializedAttribute(ValidationException.java:1121)
at org.eclipse.persistence.internal.jpa.metadata.converters.SerializedMetadata.process(SerializedMetadata.java:99)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processSerialized(MappingAccessor.java:1807)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processJPA Converters(MappingAccessor.java:1586)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processMappingConverter(MappingAccessor.java:1652)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processMap pingValueConverter(MappingAccessor.java:1670)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor.process(BasicAccessor.java:414)
at org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor.processMappingAccessors(MetadataDescriptor.java:1461)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.processMappingAccessors(ClassAccessor.java:1526)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processMappingAccessors(EntityAccessor.java:1085)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:645)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1718)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:536)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:550)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1484)
... 5 more
最佳答案
部分学习过程用于读取堆栈跟踪。您需要的行是:
Exception Description: The type [class java.lang.Object] for the attribute [hireDate] on the entity class [class model.Employee] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
Employee
类是什么样的?
编辑
正如 Chris 所指出的,您的属性不是可序列化的。将日期设置为 java.util.Date、java.util.Calendar 或 java.sql.Date。前 2 个需要带有 TemporalType 的 @Temporal 注释。这些中的每一个都将允许您的示例运行,但您应该了解将存储的内容的差异。
您还应该将其他属性更改为可序列化类型,例如 jobTitle 的 String。
希望对你有帮助
关于java - PersistenceUnit 的预部署因 EclipseLink 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944362/
我正在阅读哈德利的 Advanced R并尝试一些东西。我正在尝试创建一个 lazy闭包函数返回一个带有提供的函数 data.frame在其环境中以及使用 with并且能够在以后提供额外的函数参数。
我有两个 ViewController。初始 ViewController 是输入和存储 URL 的地方。此初始 ViewController 的 viewDidLoad 还应该在应用程序启动时开始加
你是怎么用的 对于应用程序中的 ListView 项也应该在设备 <11 上运行? 由于 activated_state 在 HC 之前不可用,我只能想到两个肮脏的解决方法: 在您的 Activit
我正在为 android (2.1 > 3.1) 编写一个应用程序,我想使用熟悉的做法,即在 Honeycomb 应用程序中使用应用程序图标来进入家庭 Activity ,但是,当我之前运行该 Act
如果搜索的键不存在,我如何覆盖方法 GET 或编写一个将在服务器端执行的新函数返回另一个键值? 示例: 如果关键字“word_1 word_2 word_3 word_4”不存在则搜索关键字“word
对于我的存储库,我使用的是 Git 和 Stash。在 Stash 端,我限制了(只读)对 master 的访问权限,因此任何用户都可以从 master 分支分支以获取功能/分支,但不能直接 merg
如何配置dgrid及其存储以定义渲染行时是否已经选择了行? 例如,如果我的行数据是这样的: { id: 1, name: 'Item Name', selected: true } 我当前
有没有一种方法可以将变量从一个 BeanShell 前/后处理器引用到另一个 BeanShell 处理器(它们在同一个线程组中)? 如果我在 HTTP 请求下的 BeanShell 预处理器中创建了一
问题 我已尝试添加预操作 shell 脚本,这些脚本会根据我正在构建的内容打开/关闭我的 .pch 文件中的某些定义。 但是,在运行构建时,没有任何反应。我不是一个流利的 shell 脚本编写者,所以
我有一个 HTML 字符串用作 jQuery 输入文档。 // the variable html contains the HTML code jQuery( html ).find( 'p' ).
在 Mercurial 中允许 merge 之前有没有办法进行一些检查? 通过将以下内容添加到 ~/.hg/hgrc,我找到了更新前 Hook ,并拥有一个在允许更新之前运行的脚本: [hooks]
总结: 预 Controller Hook 是否在缓存期间执行?是否有任何 Hook 点可以执行? (系统前?) 我应该强调一个事实,即 Hook 不会影响发送到浏览器的内容。这不是问题。 详细版:
我正在使用适用于 android 的 Skobbler Map API,到目前为止它一直非常好。按照官方的“操作方法”,我已经能够将 map 应用到我的应用程序中。比我可以让应用程序下载 map 并离
当我安装bcrypt时我的 hapi js 项目的模块尚未安装,它显示类似 node-pre-gyp install --fallback-to-build 我尝试通过运行来安装; npm i nod
我试图使用此代码的变体: apply plugin: 'java' apply plugin: 'idea' idea.workspace.iws.withXml { provider ->
假设我们有一个 PHP 项目,其依赖项 A 和 B 分别依赖于 PHP 库 X,但版本不同。 通常,人们会使用诸如 composer 之类的 PHP 依赖管理器,它可以通过在与 A 和 B 兼容的版本
这似乎违背了代码块的目的,但我希望能够在代码块中加粗。例如,如果我想将返回行加粗: int main(void) { **return 0;** } 最佳答案 您必须在 HTML 中执行此操作
我们是否应该使用 Huggingface(预)训练一个 BERT 无框模型的小写输入数据?我查看了 Thomas Wolf ( https://github.com/huggingface/trans
我有两个模式: 技能: var mongoose = require("mongoose"); var SkillSchema = new mongoose.Schema({ skill: {
我这里有问题。这适用于 Chrome,但我无法在 IE11 的 index.html 中使用任何动画。当它不想工作时,我会看到一个静态屏幕。同样在 IE 中,消息不会像它应该的那样消失。如果我将 di
我是一名优秀的程序员,十分优秀!