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

Gail Badner gbadner at redhat.com
Fri Mar 9 18:07:04 EST 2012


The documentation in 12.1.1 is correct. Read-only entities can be created and deleted.

Sounds like you can't delete a single entity from the 2nd-level cache though. That sounds like a bug.

----- Original Message -----
> From: "Steve Ebersole" <steve at hibernate.org>
> To: "Strong Liu" <stliu at hibernate.org>
> Cc: "Hibernate hibernate-dev" <hibernate-dev at lists.jboss.org>
> Sent: Friday, March 9, 2012 4:16:16 AM
> Subject: Re: [hibernate-dev] immutable can be deleted? and should readonly cache throw exception?
> 
> 
> Immutable entities should still be deletable.  Unless Gail changed
> that
> during the consolidation with making a particular entity instance
> "read
> only" as part of a session.  There was a lot of discussion at that
> time
> wrt consistency between these two things.  I forget all the outcomes.
> But immutable used to mean it could still be deleted.
> 
> HQL bulk deletes and updates circumvent normal modes of operation at
> many levels, caching being one of them.  It interacts with the cache
> in
> a much different way than a normal Session.delete.
> 
> Marking an entity with a cache access strategy of read-only is a bit
> different semantic.
> 
> +1000 about test method independence.  This has bitten us over and
> over
> again.
> 
> On Fri 09 Mar 2012 01:24:57 AM CST, Strong Liu wrote:
> > 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
> >
> > _______________________________________________
> > hibernate-dev mailing list
> > hibernate-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
> 
> --
> steve at hibernate.org
> http://hibernate.org
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
> 



More information about the hibernate-dev mailing list