我在尝试将实体类持久化到Oracle数据库时遇到错误。这是我的实体类
package com.airline.models;
import java.io.Serializable;
import java.time.LocalDate;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;
/**
* Entity implementation class for Entity: Passenger
*
*/
@Entity
public class Passenger implements Serializable {
@Transient
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "PASSENGER_SEQ")
@SequenceGenerator(name="PASSENGER_SEQ",sequenceName="PASSENGER_SEQ1", allocationSize=1)
private Integer id;
private String firstName;
private String lastName;
private LocalDate dob;
@Enumerated(EnumType.STRING)
private Gender gender;
@Enumerated(EnumType.STRING)
private FlightClass flightClass;
...
}
以及为LocalDate类型实现AtributeConverter的类
package com.airline.converter;
import java.time.LocalDate;
import java.sql.Date;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter(autoApply = true)
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
@Override
public Date convertToDatabaseColumn(LocalDate locDate) {
return (locDate == null ? null : Date.valueOf(locDate));
}
@Override
public LocalDate convertToEntityAttribute(Date sqlDate) {
return (sqlDate == null ? null : sqlDate.toLocalDate());
}
}
然而,当我试图坚持它时,我收到了这个错误:
>
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.qualifier): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00942: table or view does not exist
Error Code: 942
Call: INSERT INTO PASSENGER (ID, DOB, FIRSTNAME, FLIGHTCLASS, GENDER, LASTNAME) VALUES (?, ?, ?, ?, ?, ?)
bind => [6 parameters bound]
Query: InsertObjectQuery(com.airline.models.Passenger@2441be63)
我正在使用Eclipse Link作为持久性单元。 Persistence.xml:
<?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="airline">
<jta-data-source>jdbc/airline</jta-data-source>
<class>com.airline.models.Passenger</class>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
</properties>
</persistence-unit>
</persistence>
如何持久保存实体类。
此致