【发布时间】:2014-05-28 14:15:25
【问题描述】:
我有 List<String> MyList 的“A”实体:
@Entity(name = "A_table")
@Inheritance(strategy=InheritanceType.JOINED)
public class A implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String RepresentativeName;
@ElementCollection
@CollectionTable(name = "MyList_Table")
private List<String> MyList;
}
在我为这个“A”实体设置值后,我想从 derby 表中删除所有这些数据。
但是我如何从 CollectionTable (MyList_Table) 中删除字符串?
我尝试通过 HQL 查询来实现,但出现错误。
List<String> strList = em.createQuery("from MyList_Table").getResultList();
...
...
错误:
MyList_Table is not mapped [from MyList_Table]
我应该如何正确地制定查询?
是否有其他方法可以删除此 CollectionTable 数据?
--------------------------------
更新:
当我使用时:List<A> objectList = em.createQuery("from A_table").getResultList();
-> 我收到错误:A_Table is not mapped [from A_Table].
所以我决定保持原样:List<A> objectList = query.getResultList().
但是,如果我尝试删除它:
for (A a:objectList)
{
if(....)
{
List<String> Mylist = a.getMyList();
em.getTransaction().begin();
em.remove(Mylist);
em.getTransaction().commit();
}
}
我得到一个错误:
org.hibernate.MappingException: Unknown entity: org.hibernate.collection.PersistentBag
所以我尝试添加"@IndexColumn" 注释:
.....
@ElementCollection
@CollectionTable(name = "A_Table")
@IndexColumn(name= "indx")
private List<String> MyList;
...
现在我得到这个错误:
org.hibernate.MappingException: Unknown entity: org.hibernate.collection.PersistentList
我该怎么办?
非常感谢!!
【问题讨论】:
标签: java hibernate jpa uielementcollection