I also recommend debugging your code through the debugger. Set a break point where you have a reference to the Repository. Look at the debugger for local variables and look at the repository. Is the type your Repository or is it a Proxy. It would be a Proxy if Transactionality was added to it.
I've seen examples where the @Transactional annotation is in the DAO and I've seen it in the Service class. The Pro Spring 3 book that I have has it in the DAO class although it makes more sense to me to have it in the service. Ok, so I changed it to be in the service which does implement an interface. I also changed the packages to scan property to be:
This did not make a difference in the error message that I am getting.
I am using NetBeans and am not familiar with the debugger. I'll work on trying to get that hooked up and see what it can tell me.
You do not need the .* on the packages to scan. This will scan sub packages.
Remove this property
You are overriding Spring which sets this to SpringSessionContext.class. If you want Spring to manage things you should not set that.
What Mark is explaining is by default Spring uses an interface based proxy. Therefore if you are going to use the @Transactional annotation and you want it to work properly you need to expose the method through an interface and access it through that interface. It is good programming style to code to interfaces anyway. You can have @Transactionals on the DAO and Service layer if you want.
That said if you want want class based proxies that is an option too but I would not worry about that just yet.
Sorry I did not mean to confuse you with that other link. Do use the AnnotationSessionFactoryBean rather than the LocalSessionFactoryBean like you originally had if you intend to use Hibernate’s annotation support.
The DriverManagerDataSource is overly basic and worthless for anything other than testing. I would consider changing that to at least use apaches BasicDataSource. You might want to set the default auto commit to false on it as well.
The rest of your config looks OK. Do add an interface for your repository and call (and autowire) by the interface not the implementation. Please show us the code that calls your service. Is your service autowired in? How are you creating it? Make sure that everything is a Spring managed bean no uses of the word 'new'.
You might also try adding this to your hibernate properties, if the above suggestions don't help.
Odd maybe I am falling asleep at the keyboard but I am not seeing the problem. You can drop the proxy-target-class="true", with what you are doing that should not be necessary. How many contexts do you have can you post your web.xml?
Yup there is your problem. You will have 2 instances of your beans due to your component scanning. In your dispatcher-servlet.xml you should only be scanning the controllers only therefore remove all the component scans from dispatcher-servlet.xml except this one.
Remember that the dispatcher servlet has its own context. The scanning of services and repositories should be in the root context only. I am actually not even sure why you are scanning the domain package at all, seems to me that nothing that is going to be picked up on a component scan should be in that package.
Ok, I took out the component scan tags from the application context file. When I took all of the component scan tags out of the dispatcher servlet file except for the reference to the controller package I got the error:
I added the component scan for the service package to the dispatcher servlet and then I got the following error for the data access object
I added the component scan for the hibernate package to the dispatcher servlet and then I got the same error that I have been getting:
I also moved the component scan for the hibernate package to the application context and still got the No Hibernate Session bound error.