Categories
Java

Using session scoped beans in Spring

Spring 2.0 added a wonderful scope to the “Singleton” and “Prototype” scopes – “Session”.
For every request, Spring will create an instance of a bean and bind it to that user throughout that user’s session. This is ideal because it keeps the HTTP-connectivity layer outside the realm of the service layer.

It was a bit of a sad moment when Spring told us to shove it when we assigned the session scope to one of our beans. The error looked like

cope 'session' is not active for the current thread; consider defining a scoped proxy for this bean
if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException

Some searching uncovered what else is needed to make session scope happen:
1. In web.xml, define a RequestContextListener, for example:

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

2. In the body of the session scoped bean, add the following element:
<aop:scoped-proxy/>

Read more.

Share
Categories
Java Oracle

Mapping Hibernate to Oracle Date fields

Sometimes less is more.
We are using Hibernate and one of the tables uses a Date field to store information on what Oracle calls ‘point in time’ – the date and time of an event. The table column was mapped to an object property specifying the property type as “date”. For some reason, that caused the application to only read and write the date part of the ‘point in time’ instead of both the date and the time.
Example:
<property name=”postDate” column=”POST_DATE” not-null=”true” type=”date” />
Thanks to the last comment in this post, I found out that if you remove the explicit type from the Hibernate mapping, the table will be read and written to with both the date and the time.
Example:
<property name=”postDate” column=”POST_DATE” not-null=”true”/>

Share
Categories
General

Tech Target is a spammer

I am a reader of the ServerSide.com – THE resource for Java development information.
Still, after registering ages ago to the site and the utter collapse of the 1and1.com (my email provider) spam filter (which still does not work) I started getting tons of email from the ServerSide.com’s parent company, TechTarget about things I care less and absolutely not about. Their unsubscribe link takes you to a page that tells you that you are unsubscribed. It even sends you an email to confirm it. And then you still get their annoying invitations to events and conferences that they organize which I naturally do not want to get.
So Tech Target now counts officially as a spammer.
Bad karma unto you, Tech Target. You suck.

Share
Share