-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many problem using Hibernate on Spring...please help me :-(
PostPosted: Thu Jun 24, 2010 6:46 pm 
Newbie

Joined: Thu Jun 24, 2010 6:23 pm
Posts: 1
Hello,
I'm really desperate...I'm doing a Spring project for a university course.

My project is very simple: there is a class named insertpoiController that manager a form that allows users to enter data into fields.
This data put into the form fields are collected in the instance variables of an object instance of the command class POI when the form is submitted by the user. Up to here I have not problem butI would also that once that the user submit the form the insert value are saved on a table of my MySql database using Hibernate.

But when I try to run my project NetBeans give me the following error message:

INFO: Error while starting bundle: file:/home/andrea/GlassFish_v3/glassfish/modules/autostart/osgi-http.jar: org.osgi.framework.BundleException: Unresolved constraint in bundle org.glassfish.osgi-http [219]: package; (&(package=com.sun.enterprise.config.serverbeans)( version>=3.1.0))
INFO: org.osgi.framework.BundleException: Unresolved constraint in bundle org.glassfish.osgi-http [219]: package; (&(package=com.sun.enterprise.config.serverbeans)( version>=3.1.0))
at org.apache.felix.framework.Felix.resolveBundle(Fel ix.java:3263)
at org.apache.felix.framework.Felix.startBundle(Felix .java:1597)
at org.apache.felix.framework.BundleImpl.start(Bundle Impl.java:915)
at org.apache.felix.framework.BundleImpl.start(Bundle Impl.java:902)
at org.apache.felix.fileinstall.internal.DirectoryWat cher.start(DirectoryWatcher.java:1027)
at org.apache.felix.fileinstall.internal.DirectoryWat cher.start(DirectoryWatcher.java:1013)
at org.apache.felix.fileinstall.internal.DirectoryWat cher.startAllBundles(DirectoryWatcher.java:1006)
at org.apache.felix.fileinstall.internal.DirectoryWat cher.process(DirectoryWatcher.java:396)
at org.apache.felix.fileinstall.internal.DirectoryWat cher.run(DirectoryWatcher.java:206)


For the use of Hibernate in my Spring project I have add the Hibernate framework in NetBeans and do the following operation:

1) I have mapped the class that contai the form field values and its instance variables with the MySql table and its column

Code:
package controller;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Entity;

@Entity
@Table(name = "poi")

public class POI {

    @Id
    @Column(name = "nome")
    private String nome;

    @Id
    @Column(name = "lat")
    private float lat;

    @Id
    @Column(name = "lon")
    private float lon;

    @Id
    @Column(name = "alt")
    private float alt;

    @Column(name = "tipologia")
    private int tipologia;

    @Column(name = "wikiLink")
    private String wikiLink;

    public float getAlt() {
        return alt;
    }

    public void setAlt(float alt) {
        this.alt = alt;
    }

    public float getLat() {
        return lat;
    }

    public void setLat(float lat) {
        this.lat = lat;
    }

    public float getLon() {
        return lon;
    }

    public void setLon(float lon) {
        this.lon = lon;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public int getTipologia() {
        return tipologia;
    }

    public void setTipologia(int tipologia) {
        this.tipologia = tipologia;
    }

    public String getWikiLink() {
        return wikiLink;
    }

    public void setWikiLink(String wikiLink) {
        this.wikiLink = wikiLink;
    }

}


2) I have created a PoiDao interface that rapresents the business logic of my dao:
Code:
package dao;

import controller.POI;

public interface PoiDao {

    public void insert(POI poi);    // Inserisce un POI nel DB come nuovo record

}


3) I have create a concrete class that implements the dao interface:
Code:
package dao;

import controller.POI;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

public class PoiHibernateDaoSupport extends HibernateDaoSupport implements PoiDao {


  @Transactional
  public void insert(POI poi){
    getHibernateTemplate().saveOrUpdate(poi);
  }

}


4) This is the form controller class in which I would injected a DAO object that could be used to make operation on the DB:

Code:
package controller;

import dao.PoiDao;
import dao.PoiHibernateDaoSupport;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import service.SavedService;

public class InsertpoiController extends SimpleFormController {

   private SavedService savedService;

   PoiDao dao;

   public void setPoiDao(PoiDao dao){
        this.dao = dao;
    }

    public void setSavedService(SavedService savedService){
    this.savedService = savedService;
}

    public InsertpoiController(){
        setCommandClass(POI.class);
        setCommandName("poi");
        setSuccessView("savedView");
        setFormView("dataInputView");
    }

    @Override
    protected ModelAndView onSubmit(Object command) throws Exception{
        POI poi = (POI) command;

        // HERE THE CODE TO PERSIST MY COMMAND OBJECT poi
       
        ModelAndView mv = new ModelAndView(getSuccessView());
        mv.addObject("savedMessage", savedService.printSaved(poi.getNome(), poi.getLat(), poi.getLon(), poi.getAlt(), poi.getTipologia(), poi.getWikiLink()));
        return mv;
    }
   
}


5) Finally this is the applicationcontext.xml file where I have defined the injection: I have defined 2 beans: PoiHibernateDaoSupport that is the concrete dao implementation for Hibernate and insertpoiController within which I inject the PoiHibernateDaoSupport bean using a setter injection:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean name="savedService" class="service.SavedService" />

    <bean id="insertpoiController" class="controller.InsertpoiController">
        <!-- setter injection using the nested <ref/> element -->
        <property name="PoiHibernateDaoSupport"><ref bean="PoiHibernateDaoSupport"/></property>
    </bean>

    <bean id="PoiHibernateDaoSupport" class="dao.PoiHibernateDaoSupport"/>

    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/poi;create=true" />
        <property name="username" value="root" />
        <property name="password" value="aprile12" />
    </bean>

    <!-- Session Factory da utilizzare per mapping attraverso JPA Annotations -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>controller.POI</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>


</beans>


But...it don't work and I don't understand why...I spend 4 days and I don't fine a solution...please help me :-(

Thanks
Andrea


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.