0
新聞Spring JPATemplate DAO。從表中刪除項目
@Entity
@Table(name = "NEWS")
@NamedQueries({
@NamedQuery(name = "News.findAll", query = "SELECT n FROM News n"),
@NamedQuery(name = "News.delete", query = "DELETE FROM News n WHERE n.newsId in(:ids)")
})
@GenericGenerator(name = "test-increment-strategy", strategy = "increment")
public class News implements Serializable {
private static final long serialVersionUID = 3330980835510468207L;
private Integer newsId;
private String title;
private String brief;
private String content;
private Date created;
private String dateCreatedString;
public News() {
}
@Id
@Column(name = "NEWS_ID")
// @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "news_seq")
// @SequenceGenerator(name = "news_seq", sequenceName = "NEWS_SEQ")
@GeneratedValue(generator = "test-increment-strategy")
public Integer getNewsId() {
return newsId;
}
DAO
@Override
@Transactional(readOnly = false)
public void removeNews(List<Integer> listOfIdNewsForDeleting) throws DAOException {
EntityManager entityManager = getJpaTemplate().getEntityManagerFactory().createEntityManager();
Query query = entityManager.createNamedQuery("News.delete");
query.setParameter("ids", listOfIdNewsForDeleting);
int deleted = query.executeUpdate();
}
它是不成功的嘗試刪除的消息。
TransactionManager
不給我交易新的EntityManager
我打電話。
但我不能使用查詢投擲JpaTemplate
。有一些想法?