File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

spring + hibernate

 
manu chaox
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have some trouble with integrating Spring and Hibernate.
First, I use JPA annotation near an entity to create db schema. My code works fine for hibernate alone. I have no persistance.xml. I hope that it isn't necessary.

Now I am trying integrate spring but I have probably a mistake in applicationContext.xml. I would like to use a solution similar to "13.3.2 Implementing DAOs based on plain Hibernate 3 API" on springframework.
Could anyone help to beginner?



My applicationContext.xml



My hibernate.cfg.xml:





My error log:


I would appreciate any help.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you define two SessionFactories in your config file. The error that you are receiving is coming from the first one, because you did not put the location of the hbm.xml into the hibernate.cfg.xml.

First choose one bean to define for us, then we can help you get that to work if it doesn't work.

Mark
 
manu chaox
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:Why do you define two SessionFactories in your config file. The error that you are receiving is coming from the first one, because you did not put the location of the hbm.xml into the hibernate.cfg.xml.

First choose one bean to define for us, then we can help you get that to work if it doesn't work.

Mark


Thank for reply.

I prefer use JPA annotations therefore I think the AnnotationSessionFactoryBean would be better for me. I have a few experiences in hibernate mapping via xml configuration files.
I would like to use declarative transactional annotation as well.

So I have edited applicationContext.xml. (All other files are without changes):


Log:

 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so it looks like you have your configuration all set up and correct.

The error you are getting is now specific to JPA/Hibernate and not a Spring issue. There is something wrong with your Mapped class. It looks like you didn't set the @GeneratedValue for the @Id correctly or, the database that you are connecting to does not have the Table in it that you are mapping your class to.

Mark
 
manu chaox
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:OK, so it looks like you have your configuration all set up and correct.

The error you are getting is now specific to JPA/Hibernate and not a Spring issue. There is something wrong with your Mapped class. It looks like you didn't set the @GeneratedValue for the @Id correctly or, the database that you are connecting to does not have the Table in it that you are mapping your class to.

Mark


It works ! Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic