[jboss-user] [EJB 3.0] - Deleting parent entity should clear out its foreign key in c
TheXFed
do-not-reply at jboss.com
Sat Mar 17 12:40:33 EDT 2007
I'm having an issue where deleting the parent entity isn't clearing out the Foreign Keys in the child entities (since I don't have cascade REMOVE from the parent to the child entities).
In my application, I will assign a category (parent) to an entry (child) and save the entry which will update the category FK. However, when I delete a category, I'd like all FKs to that category in the entries collection to be cleared out.
Currently when deleting a Category (that I just loaded, which has a couple of Entries in its collection) I only see a "delete from category where ..." SQL statement being executed. I'd expect to also see a couple "update entry set category_id=null where ..." so the FKs get cleared out.
I tried to use the JoinColumn annotation on the Entry side to see if that would help, but that didn't seem to change any behavior:
@JoinColumn(name="category_id", insertable=true, updatable=true, nullable=true)
Any help would be much appreciated.
| // ************* CATEGORY ENTITY (parent) ******************
|
| @Entity
| @Table(name="category")
| public class Category extends BaseEntity {
| ...
| @Id
| @GeneratedValue(strategy=GenerationType.TABLE, generator="hilo")
| @TableGenerator(name="hilo", table="HIBBY_KEY", initialValue=100,
| pkColumnValue="category", pkColumnName="table_name", valueColumnName="next_hi", allocationSize=1)
| private Long id;
| @OneToMany(mappedBy="category")
| public Collection<Entry> entries;
|
| ...
| }
|
|
| // ************* ENTRY ENTITY (child) ******************
| // (Subclasses of this entity don't have anything significant in them)
| @Entity
| @Table(name="entry")
| @DiscriminatorColumn(name="entry_type", discriminatorType=DiscriminatorType.STRING, length=1)
| public abstract class Entry extends BaseEntity {
| ...
| @Id
| @GeneratedValue(strategy=GenerationType.TABLE, generator="hilo")
| @TableGenerator(name="hilo", table="HIBBY_KEY", initialValue=100,
| pkColumnValue="entry", pkColumnName="table_name", valueColumnName="next_hi", allocationSize=1)
| private Long id;
| @ManyToOne(optional=true, fetch=FetchType.EAGER)
| public Category category;
|
| ...
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029051#4029051
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029051
More information about the jboss-user
mailing list