Educating the world

Our blog has over 10,000 readers a month

Beginnings and endings

February 2nd, 2012

I was given the synopsis to Brave New World as follows:

Set in the 7th century AF (After Ford). Brave New World paints a grim picture of a future world in which human embryos are hatched in incubators and conditioned to collectivism and passivity. Bernard Marx, an unorthodox and unhappy ‘alpha-plus’ returns to London with a ’savage’ from New Mexico. Having educated himself by reading Shakespeare and the like, the savage believes in individual freedom and in this new world goes berserk and kills himself.

and asked to choose a style of writing (SciFi/Comedy/Horror/etc) and create an opening. I’d never heard of Brave New World which probably helped because I only had the synopsis to go on. I chose Science Fiction and here’s my beginning:

New beginning of Brave New World
“What’s the current percentage split?”
“55% male.”
“Ok, we’d better make this batch female then, pass the oestrogen supplement injector.”
Jones leaned over the counter and passed a thick hypodermic contraption to Doctor Marx who squeezed the contents into the vat and gave it a stir.
“That ought to do it. Set the timer for 6 hours and we’ll call it a night.”

Dr. Bernard Marx had been working at Fry’s People Farm for 12 years and the crushing responsibility was slowly getting to him. Each batch could only be pushed towards a gender and it was tough keeping the balance. Only a few millilitres out could result in a wasted generation. He needed a break. Science was a single man’s game and he needed something to distract him from the monotony of the Farm.

“Goodnight Jones, see you tomorrow.”
“Goodnight sir".

Marx was tired. His head was hanging like a puppet with broken strings. He dragged himself into the airlock separating the sterile laboratory and entered the Aplha’s locker room.

Next we had to create an ending to The Living and the Dead. I’d never heard of this book either, so I had no pre-conceptions. Didn’t have time to copy the synopsis but I’m sure you can find it on the inter-web.

New ending to The Living and the Dead
Eden wept. Tears rolled down her face. It had been 10 years since her mother had died, but the grief was still as real now as it was when the bombs dropped. Eden still had her mother’s name so from that respect she was different but she couldn’t help feeling like a failure. She had made her choices and she had to accept them now. It looked like another war was coming but in spite of everything she was happy.

3D Spirals

January 31st, 2012

You know how I love my optical illusions so here is a nice one from Mozilla. When I saw it first I just saw a mess of concentric circles. Now whenever I look at it, I can only see the 3D shape.

Active Spring transaction synchronization or active JTA

January 30th, 2012

During Spring development I got this exception, but there was almost no reference to what caused it. So after a lot of searching I found out the cause and thought I’d blog it for others struggling with the same problem.

java.lang.IllegalStateException: Active Spring transaction synchronization or active JTA transaction with specified [javax.transaction.TransactionManager] required
 at org.hibernate.type.CustomType.nullSafeSet(
 at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(
 at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(
 at org.hibernate.persister.entity.AbstractEntityPersister$3.bindValues(
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(
 at org.hibernate.action.EntityIdentityInsertAction.execute(
 at org.hibernate.engine.ActionQueue.execute(
 at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(
 at org.hibernate.event.def.AbstractSaveEventListener.performSave(
 at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(
 at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(
 at org.hibernate.impl.SessionImpl.saveOrUpdate(
 at org.hibernate.impl.SessionImpl.saveOrUpdate(
 at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(
 at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(
 at org.jacorb.poa.RequestProcessor.invokeOperation(
 at org.jacorb.poa.RequestProcessor.process(

In order to add large binary objects to a hibernate persistent store (database), the action must be part of a transaction.

In the springframework you must have several beans set up. The first is a datasource bean. This describes how to talk to the database; what language to use, and how to access it.


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://localhost:3306/myDb"/>
  <property name="username" value="myUsername"/>
  <property name="password" value="myPassword"/>

The default behaviour of the DriverManagerDataSource is to use database transactions if possible. However you need a transaction manager inside the spring application to manage the transaction as a whole; i.e. there may be more transactional units other than a database transaction that need to be tied together, such as a Java Message Queue Transaction. It is this overall Transaction manager that controls whether a particular transaction is committed or rolled back.

Spring provides a factory for creating (or reusing already existing) transaction objects depending on the code we are currently running through.


<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />

The transaction manager organises the rules of how one transaction interacts with another, for example we don’t want to fail a larger transaction because a smaller unit of work fails - we would want to retry the smaller transaction several times before failing the larger transaction. The transaction manager manages this.


<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
  <property name="userTransaction">
    <ref local="jotm" />

We would like to use annotations in our code so we will need to tell the xml engine how to understand <tx : ??> namespace tags.



Next we set the transaction manager to use when we use transaction annotations in our code.


&lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

Large binary objects need to run inside a transaction because they may have several stages that need to be completed before we can continue. If one of the stages fails, we need to be sure that the system will be able to clean up after us. Spring enforces this as a requirement.

We need a bean to manage the handling of a Large Object (LOB). Spring’s job is to abstract away the complexities of handling 3rd party APIs. Different databases handle LOBs in different ways so we need a LOB handler to take care of them for us:


&lt;bean id="defaultLobHandler" class=""/&gt;

We are going to use Hibernate as our object persistence store, so we need a session factory to get our Hibernate sessions. The Session Factory needs to know how to talk to the database and how to handle LOBs. We’ll use a bean for that.


&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
  &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;property name="lobHandler" ref="defaultLobHandler"/&gt;
  &lt;!-- other properties --&gt;

Unfortunately I wrote this ages ago but never finished it and never published it. I don’t work in this area any more and don’t have the will power to get back into Spring. So I publish it uncompleted with just a reference to what I was going to put in it. Maybe the first part will give help to some one looking for the meaning of the exception.

show an hbm mapping for the database
show a pojo using input stream
show doa using @Transaction
without @Transactional you get the error.

Direct and indirect discourse

January 27th, 2012

The last couple of lessons have centred around dialogue.

We had also been discussing how the descriptive text surrounding the dialogue can change everything. I tried to create the same scenario with the same characters but couldn’t quite manage it. The original idea was to have 2 passages which present a different view of the same situation and alter the readers perspective by altering the flowering around the dialogue.

I was going to link direct and indirect discourse to Wikipedia but surprisingly their definitions didn’t seem to fall in line with what teacher said. In fact I couldn’t find a good explanation of what direct and indirect discourse was from Google’s first page. So I provide these passages for you as examples. Can you spot which is direct discourse and which is indirect discourse?

First timer

Professor James Monroe slowed the car to a stop. There was almost nobody around. Shadows hid the space between the pavement and the factory doorways. Street lamps flickered and buzzed. The council hadn’t been here for a while.
A woman approached James’ passenger window and tapped on the glass with her ring.
“What do you want?", she asked in a quiet but bold voice.
This was James’ first time down Loose Lover’s Court. Trying to hide inside the car he said sheepishly, “Not really sure, what do you do?".
The woman listed the standard services with prices for each.
“We can talk about any specialist requests you might have, but we can do that later.”
James took a moment to think. Sweat was running down the sides of his waist. He felt so far out of his comfort zone that he started to shake. The woman leaned in through the window and with a comforting voice said, “Don’t worry, I’ll look after you, it’ll be all right. We don’t have to do anything you’re not comfortable with; we can just talk if you like.”
James looked visibly relieved. “Okay” he said.

Just starting

Jane Bishop was sitting behind her desk looking around her new office. The broom cupboard she had when she was a lecturer was pitifully small compared to a professor’s office.
There was a gentle knocking at the door. “What do you want?” she shouted.
The door opened a jar and a young man stuck his head around.
“Not really sure, what do you do?", he said with a nervous voice that kept cutting out.
Jane had gone to a lot of trouble to get her name and job title embossed on her office door and was about to launch into a diatribe about students walking around with their eyes closed when she noticed a guide dog sniffing at his heals. She took a breath and explained her new position with obvious glee which was clearly lost on John. She when on to explain which philosophy courses they ran at the college and finished with “We can talk about any specialist requests you might have, but we can do that later.”
John seemed at ease, but Jane felt guilty about what she almost said. She re-assured him with “Don’t worry, I’ll look after you, it’ll be all right. We don’t have to do anything you’re not comfortable with; we can just talk if you like.”
“Okay", said John, pleased that he wouldn’t have to do any writing.

I include my first attempt at the “Just starting” story but I had to bin it half way through because I felt like I had got myself into a pickle.

Second story first draft

Professor James was absently staring out of the window of his new office when there was a knock on his door. Before he could say anything the door flew open and his latest project walked in. Maria was a prostitute from the east end of town. She was on her third strike and has been told to co-operate or it was jail.
“What do you want?” she snapped impatiently. She didn’t want to be there, but for her there was no choice.
James didn’t know who the police would be sending, he only knew the area of town they’d be from.
“Not really sure, what do you do?".
She explained that she’d been busted last week for solicitation and possession. James explained that he was writing a book about the underworld and he’d needed her help.

I tried to think of situations that would allow the man to say “We can talk about any specialist..” but struggled so I started again.

Teacher and class comments
First timer

  1. Easier to visualise.
  2. Good use of indirect discourse which maintained the pace of the story.
  3. Story showed her sensitivity.
  4. Good use of “Showing” when talking about Monroe sweating.

Just starting

  1. Difficult to follow.
  2. Very quickly the story reveals lots of facts about the Professor: happy, new job, etc.
  3. Clever plot twist making John blind, no one expected that.

Both stories

  1. Introduced people early.
  2. Most of the class enjoyed the Just starting better.
  3. The tension was palpable.

Second story first draft

  1. “Latest project” liked that, good twist.
  2. Didn’t need to say she was a prostitute because it would be referred to later in the passage.

Writing can change the world

January 25th, 2012

This phrase was thought up by Stephen Fry. He enlisted the help of the engraver Graham Short to write it on the side of a fountain pen which would be auctioned in aid of English Pen the body that represents imprisoned writers around the world:

Waggled in the right way this inky little stick can change the world.