-->
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.  [ 2 posts ] 
Author Message
 Post subject: [gelöst] Keine Session vorhanden?
PostPosted: Mon Sep 27, 2010 9:19 am 
Newbie

Joined: Wed Sep 22, 2010 6:56 am
Posts: 6
Hallo, ich arbeite mit Hibernate 3, Spring 3.0.2 und MySQL um eine Webanwendung nach MVC zu erstellen.

beim Versuch eine Verbindung zur Datenbank aufzubauen erhalte ich eine NullPointerException. Ich hoffe es kann mir jemand weiterhelfen, denn ich bin mit meinem "Latein" am Ende.

dispatcher-servlet.xml:
Code:
<beans [...]>

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
       
    <bean id="idTest01Controller" class="web.test01Controller">
        <property name="geschaeftslogik" ref="idGeschaeftslogik" />
    </bean>

    <bean id="idTest02Controller" class="web.test02Controller">

    </bean>

    <bean id="idIndexController" class="web.indexController">
        <property name="formView" value="index" />
        <property name="geschaeftslogik" ref="idGeschaeftslogik" />
    </bean>

    <bean id="idGeschaeftslogik" class="bsnss.Geschaeftslogik">
        <property name="periodEntry" ref="idPeriodEntryDAO" />
    </bean>

    <bean id="idPeriodEntryDAO" class="dao.PeriodEntryDAO">
        <property name="hibernateTemplate" ref="idHibernateTemplate" />
    </bean>

    <bean id="idHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="hibernateProperties">
        <value>
            hibernate.dialect=org.hibernate.dialect.MySQLDialect
            hibernate.show_sql=true
            hibernate.format_sql=true
            hbm2ddl.auto=update
            </value>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>db.CounterWert</value>
                <value>db.GlobalSensor</value>
                <value>db.MeldungInfo</value>
                <value>db.MeldungTypInfo</value>
                <value>db.PeriodEntry</value>
                <value>db.ProfileList</value>
                <value>db.User</value>
            </list>
        </property>
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/index.disp">idIndexController</prop>
                <prop key="/test01.disp">idTest01Controller</prop>
                <prop key="/test02.disp">idTest02Controller</prop>
            </props>
        </property>
    </bean>
   
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />
   
    <bean name="indexController"
          class="org.springframework.web.servlet.mvc.ParameterizableViewController"
          p:viewName="index" />
   
</beans>


apllicationContext.xml:
Code:
<beans [...]>
    <bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://***" />
        <property name="username" value="***" />
        <property name="password" value="***"/>
    </bean>

    <bean id="hibernateSessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="datasource" />
      <property name="configLocation">
         <value>classpath:hibernate.cfg.xml</value>
      </property>
   </bean> 


PeriodEntry.java:
Code:
@Entity
@Table(name="periodeEntry")
public class PeriodEntry implements Serializable {

    private BigInteger id;
    private BigInteger profileList_Id;
    private String objName;
    private int unit;
    private int scaler;
    private String value;
    private String valueSignature;

    public PeriodEntry(){ }

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public BigInteger getId() {
        return id;
    }

    public void setId(BigInteger id) {
        this.id = id;
    }

    @Basic(optional=false)
    public String getObjName() {
        return objName;
    }

    public void setObjName(String objName) {
        this.objName = objName;
    }

    @Basic(optional=false)
    public BigInteger getProfileList_Id() {
        return profileList_Id;
    }

    public void setProfileList_Id(BigInteger profileList_Id) {
        this.profileList_Id = profileList_Id;
    }

    @Basic(optional=false)
    public int getScaler() {
        return scaler;
    }

    public void setScaler(int scaler) {
        this.scaler = scaler;
    }

    @Basic(optional=false)
    public int getUnit() {
        return unit;
    }

    public void setUnit(int unit) {
        this.unit = unit;
    }

    @Basic(optional=false)
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Basic(optional=true)
    public String getValueSignature() {
        return valueSignature;
    }

    public void setValueSignature(String valueSignature) {
        this.valueSignature = valueSignature;
    }
}


PeriodEntryDAO.java:
Code:
public class PeriodEntryDAO extends HibernateDaoSupport implements I_PeriodEntryDAO{

    private SessionFactory sessionFactory;

    public List<PeriodEntry> selectAll() {
        System.out.println("test \"PeriodEntryDao.selectAll()\"");
        try{
            Session session = sessionFactory.getCurrentSession(); //Hier kommt die NullpointerException
            System.out.println(session);
            if(session==null){
                session=sessionFactory.openSession();
            }
            session.beginTransaction();
            System.out.println(session);
            return getHibernateTemplate().loadAll(PeriodEntry.class);
           
        }
        catch(HibernateException ex){
            System.out.println(ex);
        }
    }
}
Hier hab ich schon auf verschiedene Wege versucht die Session zu bekommen, aber nichts hat funktioniert.

GeschaeftsLogik.java:
Code:
public class Geschaeftslogik implements Serializable{

    private I_PeriodEntryDAO periodEntry;

    public void setPeriodEntry(I_PeriodEntryDAO periodEntry) {
        this.periodEntry = periodEntry;
    }
   
    public List selectAllPeriodEntry(){
        return periodEntry.selectAll();
    } 
   
}



Ich bin für jede hilfreiche Antwort dankbar.

P.S: sollte noch eine Quelldatei fehlen, bitte Bescheid geben


Top
 Profile  
 
 Post subject: Re: [gelöst] Keine Session vorhanden?
PostPosted: Tue Sep 28, 2010 4:27 am 
Newbie

Joined: Wed Sep 22, 2010 6:56 am
Posts: 6
wenn ich das HibernateTemplate nutze brauch ich gar keine Session -.-

hab meine periodEntryDAO.java geändert:
Code:
public class PeriodEntryDAO extends HibernateDaoSupport implements I_PeriodEntryDAO{

    public PeriodEntry getPeriodEntry(BigInteger id) {
        return getHibernateTemplate().get(PeriodEntry.class, id);
    }

    public List<PeriodEntry> selectAll() {
        System.out.println("test \"PeriodEntryDao.selectAll()\"");
        try{
            return getHibernateTemplate().loadAll(PeriodEntry.class);     
        }
        catch(HibernateException ex){
            System.out.println(ex);
            return null;
        }
    }
}


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

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.