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

Endre Jeges (JIRA) noreply at atlassian.com
Mon Mar 31 10:29:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29913 ] 

Endre Jeges commented on ANN-721:
---------------------------------

Oh I forgot. The error message is caused by the flush method call:

	public void testPersistCascade() {
		final SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
		final Session sess = sessionFactory.openSession();
		try {
			final Transaction trx  = sess.beginTransaction();
			try {
				final Set<PersonPair> setOfPairs = new HashSet<PersonPair>();
				setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")));
				sess.saveOrUpdate(new CodedPairHolder("CODE", setOfPairs));
				sess.flush();
			} finally {
				trx.rollback();
			}
		} finally {
			sess.close();
		}
	}


The same happens for entity mananger test.

> ManyToOne Persisting Cascade in Embeddable
> ------------------------------------------
>
>                 Key: ANN-721
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-721
>             Project: Hibernate Annotations
>          Issue Type: Bug
>    Affects Versions: 3.3.1.GA
>         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
>         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.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list