• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

spring + hibernate

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic