Dear fellow programmers, I came to you for support with the following:
I use EclipseLink as ORM for my application and try to implement Soft Delete on one of my objects (articles) and cascade to delete these articles when the Catagory connection with OneToMany is removed.
When I delete an article, everything works as expected, but when I delete a category that has n articles, I get an exception. I am using DescriptorCustomizer to execute Soft Deletes.
DescriptorCustomizer (see org.eclipse.persistence.config.DescriptorCustomizer) with the following implementation:
public class ArticleCustomizer implements DescriptorCustomizer { @Override public void customize(ClassDescriptor classDescriptor) throws Exception { classDescriptor.getQueryManager().setDeleteSQLString("UPDATE article SET ACTIVE = '0' WHERE id = #id"); } }
The objects I'm trying to save are:
AbstractItem
@Entity @Table(name = "item") @Inheritance(strategy = InheritanceType.JOINED) public abstract class AbstractItem extends BaseEntity { @ManyToOne protected Category category; }
Article
@Entity @DiscriminatorValue("article") @Customizer(value=ArticleCustomizer.class) public class Article extends AbstractItem { }
Category
@Entity @Customizer(value=CategoryCustomizer.class) public class Category extends BaseEntity { @OneToMany(cascade = CascadeType.REMOVE) @JoinTable(name = "category_items", joinColumns = @JoinColumn(name = "category_id"), inverseJoinColumns = @JoinColumn(name = "item_id")) protected List<AbstractItem> items = new ArrayList<AbstractItem>(); @OneToMany(cascade = CascadeType.REMOVE) @JoinTable(name = "category_subcategories", joinColumns = @JoinColumn(name = "category_id"), inverseJoinColumns = @JoinColumn(name = "parent_category_id")) protected List<Category> categories = new ArrayList<Category>(); }
An error occurred while trying to cascade a category that has n articles:
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ACTIVE' in 'field list' Error Code: 1054 Call: UPDATE article SET ACTIVE = '0' WHERE id = ? bind => [null]
I see that the identifier was null bound, however I don't understand why. Can someone help me in the right direction?
- Eclipselink Version: 2.4.0
- Spring: 3.1.2RELEASE
Thanks!