内部异常:java.sql.SQLSyntaxErrorException:' EMAIL'不是表格中的列

时间:2016-08-15 14:53:27

标签: java sql java-ee

我正在使用Maven和Netbeans运行JAVA EE应用程序

显然我的专栏"电子邮件"没有被发现?我做错了什么?

这是在我的实体类Customers

package com.mycompany.carsales;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;

@Entity
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id ;
    private String firstName;
    private String lastName;
    private String email; //email address
    private String phone; //phone number
    @JoinColumn(name="order_of")
    @OneToMany (cascade = {CascadeType.PERSIST, CascadeType.REMOVE})

private List<CustomerTransaction> customerT;

public List<CustomerTransaction> getCustomerT() {
    return customerT;
}

public void setCustomerT(List<CustomerTransaction> customerT) {
    this.customerT = customerT;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}


public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}





@Override
public String toString() {
    return "com.mycompany.carsales.Customer[ id=" + id + " ]";
}

} 这是在我的主要

    package com.mycompany.carsales;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import com.mycompany.carsales.Customer;
import java.util.ArrayList;
import java.util.Date;
import javax.persistence.*;
/**
 *
 * @author carlos
 */
public class Main {

    public static void main (String[] args){
 // Gets an entity manager and a transaction
        Cars car = new Cars(); //creating Games object and passing values to all it
        car.setBrand("Toyota");
        car.setDescription("Manual, Red color");
        car.setType("Truck");
        car.setcYear("2014");

        Automobile auto = new Automobile();
        auto.setPrice(20000);
        auto.setPlate("88PLATE");

        CustomerTransaction transaction1 = new CustomerTransaction(); //first CustomerOrder object with Games object passed in
        transaction1.setCarPlate(auto.getPlate());
        transaction1.setCarPrice(auto.getPrice());
        transaction1.setTransactionID(auto.getId());
        transaction1.setBuyDate(new Date());

        CustomerTransaction transaction2 = new CustomerTransaction(); //first CustomerOrder object with Games object passed in
        transaction2.setCarPlate(auto.getPlate());
        transaction2.setCarPrice(auto.getPrice());
        transaction2.setTransactionID(auto.getId());
        transaction2.setBuyDate(new Date());

        ArrayList<CustomerTransaction> tList = new ArrayList(); //The arrayList is created
        tList.add(transaction1); //here the previous orders are added one by one
        tList.add(transaction2);

 Customer customer = new Customer();
customer.setFirstName("Homer");
customer.setLastName("Simpson");
customer.setEmail("Homer.Simpson@fakeemail.com");
customer.setPhone("0404944165");
customer.setCustomerT(tList);





EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyPU");
        EntityManager em = emf.createEntityManager(); //creation of Entity manager
        EntityTransaction tx = em.getTransaction(); //beginning the Entity Transaction
        tx.begin();
        //persistence performed
        em.persist(auto);
        em.persist(customer);
        //commiting transaction and closing Manager
        tx.commit();
        em.close();
        emf.close();
        System.out.println("Persistance is successfull");
    }
}

我的持久性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="MyPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.mycompany.carsales.Customer</class>
    <class>com.mycompany.carsales.Cars</class>
    <class>com.mycompany.carsales.Automobile</class>
    <class>com.mycompany.carsales.CustomerTransaction</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/Cars;create=true"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

0 个答案:

没有答案