82

I am using Hibernate to persist this bean.

import javax.persistence.*;

@Entity
public class Person {
    @Id @GeneratedValue
    private int id;
    @Column
    private String name;
    @OneToOne
    private Address addr;
}

What is the CascadeType for addr?

wannik
  • 12,212
  • 11
  • 46
  • 58

2 Answers2

121

CascadeType defaults to the empty array . See CascadeType in Annotation Type OneToOne

By default no operations are cascaded.

Sandeep Pathak
  • 10,567
  • 8
  • 45
  • 57
  • 1
    Does it work for the JPA, i'm hoping it is the same. – Zeus Jan 13 '14 at 22:38
  • 2
    JPA is the specification. Hibernate is an implementation of this specification, just as e.g. EclipseLink. So, yes. If it is in the documentation of the spec, it should be the same for all implementations. – Nico Van Belle Feb 15 '17 at 11:14
  • 1
    @NicoVanBelle this is not always the case. The default values may vary. Example the manyToOne and the oneToOne annotation in JPA have an eager default fetching mode while in hibernate it is a lazy fetching mode. – ihebiheb Dec 30 '17 at 23:07
  • @ihebiheb https://stackoverflow.com/questions/26601032/default-fetch-type-for-one-to-one-many-to-one-and-one-to-many-in-hibernate/42168093#42168093. But yes you still might want to check the implementation documentation to see if no spec defaults where overridden. Even though that is, after all, bad practice in my opinion. – Nico Van Belle Dec 31 '17 at 12:50
28

You can check the source of @OneToOne at here . No operations are cascaded by default

  /**
     * (Optional) The operations that must be cascaded to
      * the target of the association.
     *
     * <p> By default no operations are cascaded.
     */
   CascadeType[] cascade() default {};

Read more: http://kickjava.com/src/javax/persistence/OneToOne.java.htm#ixzz1d6ZWMM2y

Ken Chan
  • 84,777
  • 26
  • 143
  • 172