La Web Imágenes Vídeos Noticias Grupos Libros Gmail Más »
Grupos visitados recientemente | Ayuda | Acceder
Página principal de Grupos de Google
Mensaje del debate org.hibernate.TransientObjectE xception: object references an unsaved transient instance - save the transient instance before flushing:

Ver analizado - Mostrar sólo mensaje de texto

Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Message-ID: <e3222978-9086-429a-ad12-8336641f5855@i72g2000hsd.googlegroups.com>
Date: Tue, 12 Feb 2008 15:31:19 -0800 (PST)
Received: by 10.150.145.20 with SMTP id s20mr52181ybd.14.1202859079482; Tue, 
	12 Feb 2008 15:31:19 -0800 (PST)
X-IP: 128.107.166.234
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) 
	Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe)
Subject: org.hibernate.TransientObjectException: object references an unsaved 
	transient instance - save the transient instance before flushing:
From: Ivan B <ibo...@gmail.com>
To: Java Web Application <javawebapp@googlegroups.com>

Hi,

I have 3 classes defined as such (I am leaving out getters and
setters:

@Entity
@Table(name = "ClassA")
public class ClassA {
	@Id
	@GeneratedValue
	@Column(name = "CLASSA_ID")
	private long id;

	private String data;

	@org.hibernate.annotations.CollectionOfElements
	@JoinTable(name = "CLASSA_MEMBERS", joinColumns = @JoinColumn(name =
"CLASSA_ID"))
	private Set<ClassB> children = new HashSet<ClassB>(0);

	@org.hibernate.annotations.CollectionOfElements
	@JoinTable( name = "CLASSC_MEMBERS", joinColumns = @JoinColumn(name =
"CLASSA_ID"))
	@Cascade( {org.hibernate.annotations.CascadeType.SAVE_UPDATE,
			   org.hibernate.annotations.CascadeType.PERSIST} )
	private Set<ClassC> children2 = new HashSet<ClassC>(0);
}

@Embeddable
public class ClassB {
	@Parent
	private ClassA parent;

	private String data;
}

@Entity
@Table(name = "ClassC")
public class ClassC {

	@Id
	@GeneratedValue
	@Column(name = "CLASSC_ID")
	private long id;

	private String data;
}

If I execute this code I get the above (re: subject) error.

@Test
	public void testCreateClassA() {
		Random rnd = new Random();
		Transaction tx = session.beginTransaction();

		Set<ClassB> set = new HashSet<ClassB>(0);
		for (int i = 0; i < 10; i++) {
			ClassB child = new ClassB(String.valueOf(i));
			set.add(child);
		}

		Set<ClassC> set2 = new HashSet<ClassC>(0);
		for (int i = 0; i < 10; i++) {
			ClassC child = new ClassC(String.valueOf(i));
			set2.add(child);
//			session.save(child);
		}

		ClassA clazz = new ClassA(String.valueOf(rnd.nextInt()), set);
		clazz.setChildren2(set2);
		session.save(clazz);
		tx.commit();
	}


If I remove the commented out line in my @Test everything works fine.
Why do I have to do this? I thought that @Cascade annotation should
take care of the problem?

Crear un grupo - Grupos de Google - Página principal de Google - Condiciones del servicio - Política de privacidad
©2009 Google