hibernate - @OneToOne and @JoinColumn, auto delete null entity , doable? -


I have two entities with the following JPA annotations:

  @Entity @Table (Name = "owner") public category owner serialized {@Id @GeneratedValue (strategy = GenerationType.AUTO) @ column (name = "id") Private long ID; @OneToOne (fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn (name = "Data_id") Private data data; } @ Entity @Table (name = "data") Serial Job {@ ID Private Long ID; to apply public category data; }  

The owner and the data is a mapping, the owner is the master. The problem occurs when I execute: owner.setData (null); OwnerDao.update (owner) ; Data_ID of the "Owner" table is empty, that's right.

But the "data" row is not automatically deleted. I have to write another datacao, and to write two more tasks (owner's responsibility. Update (Owner); DatadaO.Delete is another type of service layer;)

Is it possible that Depending on your Hibernate version, use it:

"post-text" itemprop = "text">

P> Documentation:

I have never put it on a singleton, but with the doctor, this should work.

  @OneToOne (fetch = fetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn (name = "data_ id") @ org.hibernate.annotations.Cascade ({org.hibernate.annotations. CascadeType.DELETE_ORPHAN}) private data data;  

or

  @OneToOne (fetch = fetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn (name = "data_id") Private data data;  

Edit: I got this so much post:

It's bad that it is not working. Two answers however describe two different ways.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -