[hibernate-dev] immutable can be deleted? and should readonly cache throw exception?

Strong Liu stliu at hibernate.org
Fri Mar 9 02:24:57 EST 2012


Hi There,

is an immutable entity can be deleted?

according to http://docs.jboss.org/hibernate/core/4.0/manual/en-US/html_single/ 

"12.1.1. Entities of immutable classes" 

"An entity of an immutable class can created and deleted the same as an entity of a mutable class."

but "5.1.1 Entity" saying:

"Some entities are not mutable. They cannot be updated or deleted by the application. This allows Hibernate to make some minor performance optimizations.. Use the @Immutable annotation."

the reason i'm asking this is this test org.hibernate.test.annotations.entity.BasicHibernateAnnotationsTest#testPolymorphism.

when running testsuite on jdk 7, the order of methods returned by getDeclaredMethods changed and can vary from run to run (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7023180), so, the order of each test case in a test class can't be guaranteed.

so, we need each test case independent.

clearly, this test case depends on the order.

I added a cleanupTest method

	@Override
	protected void cleanupTest() throws Exception {
		Session s = openSession();
		s.beginTransaction();
		List list = s.createQuery( "from java.lang.Object" ).list();
		for(Object obj :  list){
			s.delete( obj );
		}
		s.getTransaction().commit();
		s.close();
	}

and get this exception:

java.lang.UnsupportedOperationException: Can't write to a readonly object
	at org.hibernate.testing.cache.ReadOnlyEntityRegionAccessStrategy.lockItem(ReadOnlyEntityRegionAccessStrategy.java:68)
	at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:84)
	at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:280)
	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
	at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:325)
	at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
	at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
	at org.hibernate.test.annotations.entity.BasicHibernateAnnotationsTest.cleanupTest(BasicHibernateAnnotationsTest.java:105)
	

btw, i'm also seeing this jira https://hibernate.onjira.com/browse/HHH-6329

change the cleanupTest to use hql (s.createQuery("delete java.lang.Object").executeUpdate();) runs successfully and no test failure.

-------------------------
Best Regards,u

Strong Liu <stliu at hibernate.org>
http://about.me/stliu/bio




More information about the hibernate-dev mailing list