Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

JPA:EclipselInk: Invalid object while persisting

I am creating a Author Entity and trying to persist, getting the ivalid object database exception. Here is my code.

@Entity
@Table(name = "AuthDetails")
public class Author {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    private String firstName;
    private String lastName;
    private LocalDate dateOfBirth;
    
    @Transient
    private Integer age;
    
    Author() {
    
    }
    
    Author(String firstName, String lastName, LocalDate dateOfBirth) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.dateOfBirth = dateOfBirth;
    }
}

Persistence.xml i have defined the Author. I am calling as below:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("bookPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();

        tx.begin();
        LocalDate date = LocalDate.of(1984, 04, 23);
        em.persist(new Author("ABC","XYZ",date));
        tx.commit();

Getting exception as below: nternal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'AuthDetails'. Error Code: 208 Call: INSERT INTO AuthDetails (ID, DATEOFBIRTH, FIRSTNAME, LASTNAME) VALUES (?, ?, ?, ?) bind => [4 parameters bound] Query: InsertObjectQuery(lok.learning.jpademo.callback.Author@2c991465) Exception in thread "main" javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.6.v20200131-b7c997804f): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'AuthDetails'. Error Code: 208

Any help

question from:https://stackoverflow.com/questions/66056822/jpaeclipselink-invalid-object-while-persisting

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...