Hibernate tries to insert collection despite use of @Transient keyword

Hibernate 5.6

My setup:

Table Profile
Table Validation
Mapping table profile_validation.

Profile mapping (.hbm.xml):


<hibernate-mapping>
    <class name="com.cl.myapp.core.rmgt.profile.business.object.RmgtProfileBVOImpl" table="rmgt_t_profile" proxy="com.cl.ilogic.core.rmgt.profile.common.business.object.RmgtProfileBVO">
	    <id name="rowguid" column="rowguid" type="java.lang.Long">
	    		<generator class="sequence">
		        <param name="sequence_name">rmgt_t_profile_rowguid_seq</param>
		    </generator>
	    </id>  
	                         
        ...        

        <set name="profileValidations" table="rmgt_t_profile_validation" lazy="false" cascade="all-delete-orphan">
            <key column="fk_profile_id" update="false" />
            <one-to-many class="com.cl.myapp.core.rmgt.profile.business.object.RmgtProfileValidationBVOImpl" />
        </set>
    </class>
</hibernate-mapping>

Profile Validation mapping (annotations)

@Entity
@IdClass(RmgtProfileValidationId.class)
@Table(name = "rmgt_t_profile_validation")
@Proxy(proxyClass = RmgtProfileValidationBVO.class)
public class RmgtProfileValidationBVOImpl implements RmgtProfileValidationBVO {

	@Id
	@Column(name="fk_profile_id", insertable = false, updatable = false)
	private Long profileId;

	@Id
	@Column(name="fk_validation_id", insertable = false, updatable = false)
	private Long validationId;

    @Column(name = "pv_post_import")
    private Boolean pvPostImport;

The IdClass:

public class RmgtProfileValidationId implements Serializable {
    private static final long serialVersionUID = 6805524598016438604L;

    private Long profileId;

    private Long validationId;

    public RmgtProfileValidationId(Long profileId, Long validationId) {
        this.profileId = profileId;
        this.validationId = validationId;
    }

    public RmgtProfileValidationId() {
    }
   // Getters & Setters omitted 
}

My problem is: when I want to create a new profile via .saveOrUpdate() that already has a profile validation attached, Hibernate tries to insert this profile validation, despite I marked the respective collection with @Transient:

RmgtProfileValidationBVOImpl:

@Transient
private java.util.Set<RmgtProfileValidationBVO> profileValidations;

Error message:

10:22:41,754 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-2) SQL Error: 0, SQLState: 22023
10:22:41,755 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-2) The column index 4 out of range. Number of columns 3.
org.springframework.dao.DataIntegrityViolationException: could not insert: [com.cl.myapp.core.rmgt.profile.business.object.RmgtProfileValidationBVOImpl]; SQL [insert into rmgt_t_profile_validation (pv_post_import, fk_profile_id, fk_validation_id) values (?, ?, ?)]; nested exception is org.hibernate.exception.DataException: could not insert: [com.cl.myapp.core.rmgt.profile.business.object.RmgtProfileValidationBVOImpl]

What the profile looks like before .saveOrUpdate()

Why is hibernate still trying to insert the Profile Validation?

Because your hbm.xml specifies that profileValidations is a one-to-many set and hbm.xml overrides annotations.

Ah, got it. What would be the .hbm.xml equivalent to @Transient annotation in an @Entity class that makes Hibernate READ the profileValidations when fetching profiles but not persisting any changes that I make to profileValidations? Maybe this?

<set name="profileValidations" table="rmgt_t_profile_validation" lazy="false" >
            <key column="fk_profile_id" update="false" not-null="true" />
            <one-to-many class="com.cl.myapp.core.rmgt.profile.business.object.RmgtProfileValidationBVOImpl" />
        </set>

You have to remove the cascading.