-->
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: eclipse hibernate tool junit
PostPosted: Tue Jan 19, 2010 5:56 pm 
Newbie

Joined: Tue Jan 19, 2010 5:33 pm
Posts: 1
Location: DE
Hi,

ich beschäftige mich erst seit kurzem mit dem Thema Hibernate und stosse immer wieder auf Probleme mit Session.
zurzeit versuche ich gerade ein reverse-engineering aus einer Sybase SQL Anywhere 11 Datenbank mit Hilfe der Hibernate Tools mit Eclipse.
Soweit so gut, die Klassen DAO und den einzelnen Klassen die die Tabellen abbilden werden generiert.

Ich scheitere einfach am Testen der einzelnen Klassen mit Hilfe von JUNIT. Weil Hibernate immer eine JNDI-Datasource
verlangt. Ich hab aber leider keine Ahnung wie ich das hinbekomme.

Source Code Domain Model (nur der Begin) :
Code:
/**
* Home object for domain model class Moduleinfo.
* @see hib.Moduleinfo
* @author Hibernate Tools
*/
public class ModuleinfoHome {

    private static final Log     log            = LogFactory.getLog(ModuleinfoHome.class);

    private final SessionFactory sessionFactory = getSessionFactory();

    protected SessionFactory getSessionFactory() {
        try {
            return (SessionFactory) new InitialContext().lookup("SessionFactory");
        }
        catch (Exception e) {
            log.error("Could not locate SessionFactory in JNDI", e);
            throw new IllegalStateException("Could not locate SessionFactory in JNDI");
        }
    }


Source Code JUNIT-Test:
Code:
    @Test
    public void test(){
        SessionFactory sessionFactory = new Configuration ().configure ().buildSessionFactory ();
        ModuleinfoHome modulinfohome = new ModuleinfoHome();
        Moduleinfo modulinfo = modulinfohome.findById(1);
        System.out.println(modulinfo.getArt());
    }
}

die letzten Zeilen der LOG-Ausgabe
Code:
22:01:27,341  INFO SessionFactoryImpl:193 - building session factory
22:01:27,640  INFO SessionFactoryObjectFactory:109 - Factory name: CUSTOMHibernateSession
22:01:27,641  INFO NamingHelper:49 - JNDI InitialContext properties:{}
22:01:27,643  WARN SessionFactoryObjectFactory:121 - Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

Exception:
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI


Mit der Bitte um Hilfe, Alex


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.