尝试将值插入我的表时,我收到此错误
org.hibernate.property.access.spi.PropertyAccessException: Error accessing
field [private int com.app.demo.model.Customer.id] by reflection for
persistent property [com.app.demo.model.Customer#id] :
com.app.demo.model.Customer@6d1c6e1e
javax.persistence.PersistenceException:
org.hibernate.property.access.spi.PropertyAccessException: Error accessing
field [private int com.app.demo.model.Customer.id] by reflection for
persistent property [com.app.demo.model.Customer#id] : com.app.demo.model.Customer@6d1c6e1e
这是我的客户表。我正在使用MySql Workbench,我试图将我的值插入到这里。
我正在使用这个类将值插入到表中
@Entity
@Table(name="customer")
public class Customer {
@Id
@GeneratedValue
@Column(name = "customer_id", unique = true, nullable = false)
private int id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@Column(name="street_address")
private String address;
@Column(name="city")
private String city;
@Column(name="state")
private String state;
@Column(name="zip_code")
private String zipcode;
@Column(name="email")
private String email;
@Column(name="paypal_email")
private String paypalEmail;
// getters and setters
这就是我如何将值插入到表中
// Set customer values
Customer valuedCustomer = new Customer();
valuedCustomer.setFirstName(firstName);
valuedCustomer.setLastName(lastName);
valuedCustomer.setAddress(address);
valuedCustomer.setCity(city);
valuedCustomer.setState(state);
valuedCustomer.setZipcode(zip);
valuedCustomer.setEmail(email);
// insert customer info into the customer table
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(valuedCustomer);
em.getTransaction().commit();
郎朗坤
Qyouu
相关分类