Using JPA entities annotations with Hibernate native API cause problem during DB persisting of relationships containing newly created Entities.
When parent has children collection annotated by @OneToMany(cascade = CascadeType.PERSIST) or @ManyToMany(cascade = CascadeType.PERSIST)
then the new child entities added to the parent collection are not persisted upon transaction commit but org.hibernate.TransientObjectException is thrown instead.
When the cascade type CascadType.ALL is used, then newly created children are correctly inserted into DB upon synchronization.
It happens only if the entities are managed using native hibernate api. When using JPA api (EntityManager) then the new child entities are persisted for both PERSIST and ALL cascading types, which is the correct behaviour according to JPA specification.
|