Spring Hibernate Session Problem

Once developing a Spring application you might stumble across the problem ‘ No Session found for current thread’.

The obvious answer is that the service does not have the @Transactional annotation when using the dao. However this is a hard to forget step.

But this problem might occur when the controller tries to access the dataService.
How come since the custom UserDetailsService that you have implemented (which uses hibernate by the way) works fine?

The problem is that when you have more than one application context files (just like having a child context for the DispatcherServlet) the configuration should be applied since you are going to use hibernate.

Tomcat Connection Pooling

With tomcat you can have Jdbc connection pooling.
You can use dbcp however there is a tomcat connection pool implementation.

Before getting started you have to put the database driver jar to the
tomcat/libs directory

For example if you use mysql you need to place the mysql-connector-java.jar inside the tomcat/libs directory

The configuration is pretty much the same however in order to use the tomcat connection pool you need to specify org.apache.tomcat.jdbc.pool.DataSourceFactory at the factory attribute.

On your META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
        <Resource type="javax.sql.DataSource"

And of course you add your choice of connection pool size, max open connections, idle connections etc.

Then you can get the DataSource object and of course a connection. which you have to close after you have your work done in order to release it back to the pool.

Context context = new InitialContext();
DataSource ds = (DataSource) context.lookup( "java:/comp/env/jdbc/baseDB" );	
Connection connection = ds.getConnection();

More on Tomcat JDBC Connection Pool

Wicket and DataView

You have a table and you want to populate it.

        <th>A num</th>
    <tr wicket:id="anumlst">
        <td wicket:id="anum"></td>

Also you have a pojo

public class Anum implements IClusterable {

    private String anum;

    public String getAnum() {
        return anum;

    public void setAnum(String anum) {
        this.anum = anum;

And then you can populate the table. On this one i use ListDataProvider

    private List<Anum> anums = new ArrayList<Anum>();

    DataView anumlst = new DataView("anumlst",new ListDataProvider(anums)) {
            protected void populateItem(Item item) {
                item.add(new Label("anum",((Anum)item.getModelObject()).getAnum()));

Thus you populate the table.
You can also make your own dataprovider (For example a dataprovider fetching data through hibernate).

Plus with dataview you can have easy paging.

You can Just add a PagingNavigator (or an AjaxPagingNavigator in case of a modal window)

Just after the end of the table tag add

<span wicket:id="pager">/span>

and at the java class

PagingNavigator pagingNavigator = new PagingNavigator("pager", anumlst);

Java and Soap

Since JDK 6 you have built in support for SOAP (SAAJ ).

There are many services that still use it, therefore consuming soap service is always usefull.

By creating a SOAP message you can add some attributes to the evlelop.

    try {
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
    } catch(SOAPException e) {

Then you can add your elements to the soap body.

    try {

        SOAPBody body = envelope.getBody();
        SOAPElement bodyElement = body.addChildElement(envelope.createName("Connect" , "ns1", ""));                                                      
        SOAPElement findItem = bodyElement.addChildElement("ItemName");
        findItem.setAttribute("xsi:type", "xsd:string");

    } catch(SOAPException e) {

After you are done you can use SOAPConnection to send your message and get the response as a SOAP message.

    try {

        SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection();
        SOAPMessage returnMessage = soapConnection.call(soapMessage,serverUrl);
    } catch(SOAPException e) {

Git repositories through ssh.

So you have an ssh server?
Great!!! Time to setup some git repos.

If you don’t already have a git user and git installed

sudo adduser -m git
sudo apt-get install git

You can use the git account either through normal password authentication or by using private and public ssh keys. Your choice :)

Then set up the repo.

cd /home/git/
mkdir mygit.git
cd mygit.git
git --bare init

And you are ready to go.
Open a terminal on your pc and just do

git clone git@yourserverip:/home/git/mygit.git

Gwt Google maps

In case you want google maps in your gwt application you can use the
gwt-google-maps-v3 since gwt-google-apis is currently alpha.

You need to add the gwt-maps.jar on the build path but also you have to add the same jar at the WEB-INF/lib directory

And of course inside your module configuration file you need to add

<inherits name="com.google.maps.gwt.GoogleMaps" />

Then you are ready to go.

private GoogleMap placeMap;
private Marker placeMarker;

public void onModuleLoad() {

RootPanel rootPanel = RootPanel.get("main");
final MapOptions myOptions = MapOptions.create();
LatLng myLatLng = LatLng.create(-34.397, 150.644);
placeMap = GoogleMap.create(rootPanel.getElement(),myOptions);


Ios and http requests

You can either use NSURLRequest or NSMutableURLRequest
the difference is that with NSMutableURLRequest you can change the url the method etc.

I will use the NSMutableURLRequest

Supposing you have a class implementation

#import "UrlFetcher.h"

@implementation UrlFetcher

-(void)setUrl:(NSString *)url
    twitterUrl = [NSURL URLWithString:url];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:twitterUrl];
    [request setHTTPMethod:@"GET"];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];    

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    NSLog(@"got data");
    NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

Since you set as the delegate the class where the method is called you need to implement the

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{}