Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javax持久性多对多集合EclipseLink JPA 2.1_Java_Jpa_Collections_Eclipselink_Derby - Fatal编程技术网

Javax持久性多对多集合EclipseLink JPA 2.1

Javax持久性多对多集合EclipseLink JPA 2.1,java,jpa,collections,eclipselink,derby,Java,Jpa,Collections,Eclipselink,Derby,使用Netbeans开发嵌入式数据库应用程序Derby。我正试图弄清楚多对多关系是如何运作的。Netbeans为我创建了实体类。我了解如何检索记录并向记录提交新结果,但我不熟悉如何提交集合。请参见下面的代码 @Entity @Table(name = "MASTER") @XmlRootElement @NamedQueries({.... }) public class Master implements Serializable { private static final long ser

使用Netbeans开发嵌入式数据库应用程序Derby。我正试图弄清楚多对多关系是如何运作的。Netbeans为我创建了实体类。我了解如何检索记录并向记录提交新结果,但我不熟悉如何提交集合。请参见下面的代码

@Entity
@Table(name = "MASTER")
@XmlRootElement
@NamedQueries({....
})
public class Master implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@Column(name = "SDS_NUMBER")
private Integer sdsNumber;
@Column(name = "PRODUCT_NAME")
private String productName;
@Column(name = "PRODUCT_DESCRIPTION")
private String productDescription;
@Column(name = "SDS_FILE_NAME")
private String sdsFileName;
@Column(name = "USE_STATUS")
private Boolean useStatus;
@Column(name = "DATA_UPDATED")
@Temporal(TemporalType.DATE)
private Date dataUpdated;
@Column(name = "PROPER_SHIPPING_NAME")
private String properShippingName;
@Column(name = "SIGNAL_WORD")
private String signalWord;
@Column(name = "GHS_COMPLIANT")
private Boolean ghsCompliant;
@JoinTable(name = "STATEMENT_LOOKUP", joinColumns = {
    @JoinColumn(name = "SDS_NUMBER", referencedColumnName = "SDS_NUMBER")},
     inverseJoinColumns = {
    @JoinColumn(name = "STATEMENT_ID", referencedColumnName = "STATEMENT_ID")})
@ManyToMany
private Collection<Statements> statementsCollection;
@ManyToMany(mappedBy = "masterCollection")
private Collection<Manufacturers> manufacturersCollection;
@JoinTable(name = "PICTOGRAM_LOOKUP", joinColumns = {
    @JoinColumn(name = "SDS_NUMBER", referencedColumnName = "SDS_NUMBER")}, inverseJoinColumns = {
    @JoinColumn(name = "PICTOGRAM_ID", referencedColumnName = "PICTOGRAM_ID")})
@ManyToMany
private Collection<Pictograms> pictogramsCollection;
@ManyToMany(mappedBy = "masterCollection")
private Collection<Locations> locationsCollection;
@ManyToMany(mappedBy = "masterCollection")
private Collection<Keywords> keywordsCollection;

public Master() {
}

public Master(Integer id) {
    this.id = id;
}  Getters and Setters follow.......
    @XmlTransient
public Collection<Keywords> getKeywordsCollection() {
    return keywordsCollection;
}

public void setKeywordsCollection(Collection<Keywords> keywordsCollection) {
    this.keywordsCollection = keywordsCollection;
}


public class NewClass {
public static void main(String[] args) {
EntityManagerFactory entityManagerFactory = 
Persistence.createEntityManagerFactory("JavaApplication20PU");
EntityManager em = entityManagerFactory.createEntityManager();
EntityTransaction userTransaction = em.getTransaction();

userTransaction.begin();
Master record = new Master();
record.setProductName("Test Product Name");
record.setProductDescription("Test Product Description");
record.setProperShippingName("Proper shipping name test");
record.setSdsNumber(999);
record.setSignalWord("WARNING");
record.setUseStatus(false);
record.setGhsCompliant(false);
record.setKeywordsCollection();// This is where I need help!
em.persist(record);
userTransaction.commit();
em.close();
entityManagerFactory.close();
}
}

上面是我的测试类中填充记录的代码。注释行是我需要帮助的地方。最终,这需要使用Jlist中的选项填充,但任何通用帮助或指向我可以更好地了解其工作原理的链接都将不胜感激。谢谢

将本教程视为一个很好的示例,您可以看到一些关于DER的工作示例

而且它不是一个Jlist,而是一个List或ArrayList,可能是打字错误XD。在测试中,您没有向主控添加关键字列表