Announcement Announcement Module
Collapse
No announcement yet.
Spring integratiom with H2 database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring integratiom with H2 database

    Hi All

    Please let me know the steps involved in integrating H2 database with Spring framework.

    I am a newbie to Spring,,,,


    Thanks

  • #2
    some one pls reply ..... need help urgently

    Comment


    • #3
      You can refer Spring documentation for how to do database access using Spring. below is the link for it.

      You can ignore sections related to Transaction management if not required in your application.

      http://static.springsource.org/sprin...ansaction.html

      Also you can find sample code snippets in this forum itself at many threads.

      -Ronak.

      Comment


      • #4
        Spring -Grails + H2 database

        I migrated my application from grails 1.0.2 to grails 1.3.5. Since then i am facing issues while executing some of the existing database queries. The data base used is H2. Following error is coming while attempting the following query" "appointment = AuditAppointment.findByAudit(currentAudit) "

        org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement:select this_.id as id573_0_, this_.version as version573_0_, this_.appointment_address_id as appointm3_573_0_, this_.appointment_contact_id as appointm4_573_0_, this_.appointment_date as appointm5_573_0_, this_.contact_date as contact6_573_0_ from audit_appointment this_ where this_.id=? [90012-143]
        at org.h2.message.DbException.getJdbcSQLException(DbE xception.java:327)
        at org.h2.message.DbException.get(DbException.java:16 7)
        at org.h2.message.DbException.get(DbException.java:14 4)
        at org.h2.expression.Parameter.checkSet(Parameter.jav a:73)
        at org.h2.command.Prepared.checkParameters(Prepared.j ava:161)
        at org.h2.command.CommandContainer.query(CommandConta iner.java:79)
        at org.h2.command.Command.executeQuery(Command.java:1 32)
        at org.h2.jdbc.JdbcPreparedStatement.executeQuery(Jdb cPreparedStatement.java:96)
        at AuditAppointmentController$_closure2.doCall(AuditA ppointmentController.groovy:38)
        at AuditAppointmentController$_closure2.doCall(AuditA ppointmentController.groovy)
        at java.lang.Thread.run(Thread.java:619)

        Following is the code:
        class Audit {
        //List parties;

        Boolean currentAudit

        AuditAppointment auditAppointments;

        String toString() {
        "Audit For: ${this.employerName}"
        }

        Class AuditAppointment contain relation (belongsTo) with Audit class
        like,
        class AuditAppointment {
        static hasMany = [appointmentHistory:AppointmentHistory,
        appointmentComments:AppointmentComment]
        static belongsTo = [audit:Audit];

        first the query "def currentAudit = Audit.findByCurrentAudit(true)" is executed.First query is returning the records.
        The results(object of Audit) are passed to the 2nd query:
        "appointment = AuditAppointment.findByAudit(currentAudit)"

        internally it creates hibernate query like, select this_.id as id573_0_, this_.version as version573_0_, this_.appointment_address_id as appointm3_573_0_, this_.appointment_contact_id as appointm4_573_0_, this_.appointment_date as appointm5_573_0_, this_.contact_date as contact6_573_0_ from audit_appointment this_ where this_.id=?

        I am new to grails and H2, not getting idea how to resolve the issue.

        Thanks,
        Ayush

        Comment


        • #5
          @Vidhya,

          Take a look at the "Embedded Database Support" section of Spring reference documentation: http://static.springsource.org/sprin...tabase-support

          In short to use H2 database with Spring, all you have to do is tell Spring about it:

          Code:
          <jdbc:embedded-database id="dataSource" type="H2"/>
          ( and define a "dataSource" bean of course )

          Here is a sample project that uses H2 to demo Spring and Hibernate integration: http://github.com/anatoly-polinsky/money-making-project

          /Anatoly

          Comment

          Working...
          X