2

アプリのウィッシュ リスト機能に追加しようとしていますが、次のエラーが発生し続けます。

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):           org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: Column 'WISH_ID'        cannot accept a NULL value.
Error Code: -1
Call: INSERT INTO WISHLIST (BOOK_TITLE, CUSTOMER_ID) VALUES (?, ?)
bind => [2 parameters bound]
Query: InsertObjectQuery(dukesbookstore.entity.Wishlist[ wishId=null ])

ENTITY クラス:

@Entity
@Table(name = "WISHLIST")
@XmlRootElement
@NamedQueries(
{
@NamedQuery(name = "Wishlist.findByCustomerId", query = "SELECT w FROM Wishlist w WHERE  w.customerId = :customerId"),

})
public class Wishlist implements Serializable
{
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) 
@Column(name = "WISH_ID")
private Integer wishId;
@Column(name = "CUSTOMER_ID")
private Integer customerId;
@Size(max = 35)
@Column(name = "BOOK_TITLE")
private String bookTitle;

public Wishlist()
{
}



public Integer getCustomerId()
{
    return customerId;
}

public void setCustomerId(Integer customerId)
{
    this.customerId = customerId;
}

public String getBookTitle()
{
    return bookTitle;
}

public void setBookTitle(String bookTitle)
{
    this.bookTitle = bookTitle;
}   
}

これは、新しいウィッシュを作成するためのコードです。

public void createWishlist(String title,int cust_id)
{
            Wishlist newWish = new Wishlist();
            newWish.setBookTitle(title);
            newWish.setCustomerId(cust_id);
            em.persist(newWish);
  }

他の同様の問題を見てみましたが、使用していない休止状態が含まれています。AUTOSEQUENCE、などの生成戦略もいろいろ試しましTABLEたが、すべて失敗しました。また、まったく同じ顧客という名前の別のエンティティがありますが、フォームから作成されても正常に機能します。

に変更すると、次のAUTOエラーが生成されます。

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):   org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'SEQUENCE' does not exist.
Error Code: -1
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [2 parameters bound]
Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
root cause

java.sql.SQLSyntaxErrorException: Table/View 'SEQUENCE' does not exist.
root cause

org.apache.derby.client.am.SqlException: Table/View 'SEQUENCE' does not exist.

関連する場合の Persistence.xml

<?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="myStorePU" transaction-type="JTA">
    <jta-data-source>mydb</jta-data-source>
    <class>myStore.entity.Book</class>
    <class>myStore.entity.Customer</class>
    <class>myStore.entity.Wishlist</class>

    <properties>
        <property name="javax.persistence.jdbc.user" value="APP"/>
        <property name="javax.persistence.jdbc.password" value="APP"/>

         <property name="eclipselink.logging.level" value="FINE"/>
    </properties>

</persistence-unit>

4

2 に答える 2