[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3218) ManyToOne Persisting Cascade in Embeddable

Gail Badner (JIRA) noreply at atlassian.com
Tue Nov 8 18:30:20 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44275#comment-44275 ] 

Gail Badner commented on HHH-3218:
----------------------------------

Endre Jeges, thanks for the test case. I've removed the Hibernate- and dialect-specific features it uses and renamed it to org.hibernate.test.annotations.cascade.CascadeToElementCollectionEmbeddedManyToOneTest.

The test reproduces this issue on the default dialect (H2Dialect).

I've pushed this test case to master, with the test itself marked as @FailureExpected.

The reason it does not cascade to the associations in the embedded colleciton elements is because EntityMetamodel.hasCascades() erroneously returns false.

Anyone care to look into why EntityMetamodel does not know about these cascades?

> ManyToOne Persisting Cascade in Embeddable
> ------------------------------------------
>
>                 Key: HHH-3218
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3218
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.2.6, 3.5.1
>         Environment: Java version:
> java version "1.6.0_04"
> Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
> Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
> Oracle Version:
> Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
> PL/SQL Release 9.2.0.8.0 - Production
> "CORE	9.2.0.8.0	Production"
> TNS for Linux: Version 9.2.0.8.0 - Production
> NLSRTL Version 9.2.0.8.0 - Production
> hibernate: 3.2.6.ga
> hibernate-annotations: 3.3.1.ga
> hibernate-commons-annotations: 3.3.0.ga
> hibernate-entitymanager: 3.3.1.ga
>            Reporter: Endre Jeges
>            Assignee: Gail Badner
>             Fix For: 4.0.0.next
>
>         Attachments: pairTest.zip
>
>
> Hello,
> I have found something that is a bit strange. For @ManyToOne association properties in an @Embeddable class the cascade PERSIST, SAVE-UPDATE option is not  working well (not sure for the other cascade types), if the entities associated with ManyToOne are transient. I have created a unit test to check it and I have it attached to this issue. It is a maven2 project, and needs Oracle to run it. If I save the associated entites, then everything works fine, also the data structure is created well.
> I have checked the forums and found similar problems, maybe they can help more then my post:
> http://forum.hibernate.org/viewtopic.php?t=965238
> http://forum.hibernate.org/viewtopic.php?t=976534
> http://forum.hibernate.org/viewtopic.php?t=978112
> http://forum.hibernate.org/viewtopic.php?t=978138
> http://forum.hibernate.org/viewtopic.php?t=983766
> http://forum.hibernate.org/viewtopic.php?t=983780
> http://forum.hibernate.org/viewtopic.php?t=983868
> Details:
> @Entity
> class CodedPairHolder {
> 	@Id
> 	private Long id;
> 	@Column(name = "CODE", nullable = false, unique = true, updatable = false, length = 256)
> 	private String code;
> 	@CollectionOfElements
> 	@JoinTable(name = "CODED_PAIR_HOLDER_PAIR_SET", joinColumns = @JoinColumn(name = "CODED_PAIR_HOLDER_ID"))
> 	private final Set<PersonPair> pairs = new HashSet<PersonPair>(0);
>         
>         ........ constructors getters equals hashCode
> }
> @Embeddable
> class PersonPair {
> 	@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
> 	@Cascade( { org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.REFRESH,
> 			org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.REPLICATE, org.hibernate.annotations.CascadeType.EVICT })
> 	@JoinColumn(name = "LEFT_PERSON_ID", nullable = false, updatable = false)
> 	private Person left;
> 	@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
> 	@Cascade( { org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.REFRESH,
> 			org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.REPLICATE, org.hibernate.annotations.CascadeType.EVICT })
> 	@JoinColumn(name = "RIGHT_PERSON_ID", nullable = false, updatable = false)
> 	private Person right;
>         ........ constructors getters equals hashCode
> }
> @Entity
> class Person {
> 	@Id
> 	private Long id;
> 	@Column(name = "NAME", nullable = false, unique = true, updatable = false, length = 256)
> 	private String name;
>         ........ constructors getters equals hashCode
> }
> The error message is:
> org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Person
> Regards,
>    jeges

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list