-->
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: factory.openSession()=>LazyInitializationException
PostPosted: Wed May 12, 2004 12:05 pm 
Newbie

Joined: Tue May 11, 2004 7:08 am
Posts: 2
I use hibernate 2.1.3 and JBoss 3.2.1


I use the following code to get a SessionFactory:

Code:
public SessionFactory getDatabase(){
try{Context context = new InitialContext();
     SessionFactory ds = (SessionFactory) context.lookup( "java:/hibernate/HibernateFactory");
System.out.println(ds);
return  ds;
}
catch(Exception e){
   e.printStackTrace();
   return null;
}
}


in an other method i use the sessionFactory to open a Session:

Code:
public Produkt createProdukt(long shopId,String stichworte, String beschreibung,
                         double verkaufsPreis,int verkaufsMenge,
                           String url, String bild) throws CreationException {
      
         //Erzeugen des 1.Produktes
         Produkt produkt;
         try{
            SessionFactory factory= getDatabase();
            Session sess = factory.openSession();
            produkt = new Produkt(stichworte,beschreibung,verkaufsPreis,
                                          verkaufsMenge,url,bild);
            Long ids = (Long)sess.save(produkt);
            factory.close();
           sess.close();
         }
         catch(Exception e){
            e.printStackTrace();
            return null;
          }
                                       verkaufsMenge,url);
            return produkt;   
   }

and now my mapping file: Person.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="webshop.code.Produkt" table="PRODUKT2">
       <id name="id" column="id" type="long">
          <generator class="hilo.int"/>
       </id>
        <property name="stichworte"/>
        <property name="beschreibung"/>
        <property name="verkaufsMenge"/>
        <property name="verkaufsPreis"/>
        <property name="url"/>
        <property name="bildUrl"/>
    </class>

</hibernate-mapping>

I get the following Exception always when factory.openSession() is executed!
    17:42:47,401 INFO [STDOUT] net.sf.hibernate.LazyInitializationException: Hibern
    ate lazy instantiation problem
    at net.sf.hibernate.jmx.SessionFactoryStub.getImpl(SessionFactoryStub.ja
    va:77)
    at net.sf.hibernate.jmx.SessionFactoryStub.openSession(SessionFactoryStu
    b.java:62)
    at webshop.utils.ShopService.createProdukt(ShopService.java:92)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:111)
    at org.jboss.aop.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotin
    gInvocationHandler.java:75)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:369)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:282)
    at org.jboss.remoting.transport.socket.SocketServerInvoker$Client.run(So
    cketServerInvoker.java:208)
    Caused by: net.sf.hibernate.MappingException: Resource: mappings/Produkt.hbm.xml
    not found
    at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:313
    )
    at net.sf.hibernate.jmx.HibernateService.buildSessionFactory(HibernateSe
    rvice.java:174)
    at net.sf.hibernate.jmx.SessionFactoryStub.getImpl(SessionFactoryStub.ja
    va:74)
    ... 11 more
I guess the server is configured correctly because there are no Exceptions during starting.
Can someone help me please? What make I wrong?[/code]


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.