users
[Top] [All Lists]

Re: [cinjug-users] Hibernate Newbie Question

To: smorgan@xxxxxxxx, users@xxxxxxxxxx
Subject: Re: [cinjug-users] Hibernate Newbie Question
From: John Olmstead <jolmstead2k@xxxxxxxxx>
Date: Wed, 28 Jul 2004 13:23:33 -0700 (PDT)
Delivered-to: mailing list users@cinjug.org
In-reply-to: <OF87EDE91A.AAB96498-ON85256EDF.006DAE51@smml.net>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Scott & Chris,

I have added the following config file to my classes directory and still get 
the same
exception trace (hibernate.config.xml):

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>

<hibernate-configuration>

  <!-- a SessionFactory instance listed as /jndi/name -->
  <session-factory  name="java:comp/env/hibernate/SessionFactory">

    <!-- properties
    <property name="connection.datasource">cintas/datasource/mlraDS</property>
    <property 
name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
    <property name="show_sql">true</property>
    <property name="use_outer_join">true</property>
    <property name="transaction.factory_class">
            net.sf.hibernate.transaction.JTATransactionFactory
    </property>
    <property name="transaction.manager_lookup_class">
        net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
    </property>
    <property  name="jta.UserTransaction">java:comp/UserTransaction</property>
-->
    <!-- mapping files -->
    <mapping resource="ems/hibernate/HibernateCompany.hbm.xml"/>
    <mapping resource="ems/hibernate/HibernateServer.hbm.xml"/>
    <mapping resource="ems/hibernate/HibernateInstance.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Thanks Again!!!!

John Olmstead


--- smorgan@xxxxxxxx wrote:

---------------------------------

 
Are your .hmb.xml files listed in your main hibernate config file?  Many times, 
I've forgotten
to add these after generating the hbm.xml files via xdoclet.

Scott


Chris Nelson <cnelson4eii@xxxxxxxxx>
07/28/2004 12:50 PM MST

 To: users@xxxxxxxxxx
 cc: 
 bcc: 
 Subject: Re: [cinjug-users] Hibernate Newbie Question
 



It does look like it is not finding your .hbm.xml
files.  These files should be place next to the class
files, ie the hbm file for class com.blah.Foo would go
in the classes dir at com/blah/Foo.hbm.xml.  I do this
by calling xdoclet and telling it to generate into my
source dir and then copy these files over to the
classes directory in my compile target.

Hibernated classes absolutely can be tested in a dev
environment, but you may need to use a different
configuration file to tell it to just connect thru
JDBC and not get the connection from the datasource.
Myself, I just run my junit test cases in the
appserver locally using cactus and DBUnit and that way
i just have one config file.

--- John Olmstead <jolmstead2k@xxxxxxxxx> wrote:
> Collegues;
>
> I have developed a demonstration application to use
> hibernate and I'm trying to test this
> application from a main method within an ide.  I'm
> getting the following error :
>
> net.sf.hibernate.MappingException: No persister for:
> ems.hibernate.HibernateCompany
> at
>
net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
> at
>
net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2686)
> at
>
net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1984)
> at
>
net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1916)
> at
>
ems.hibernate.EmsHibernateFacade.getServers(EmsHibernateFacade.java:70)
> at
>
ems.hibernate.EmsHibernateFacade.main(EmsHibernateFacade.java:36)
> java.lang.NullPointerException
> at
>
ems.hibernate.EmsHibernateFacade.main(EmsHibernateFacade.java:37)
>
> I'm betting that the application does not see the
> hbm.xml files I generated with XDoclet. How
> do I get the application to see the hbm.xml files?
> Can hibernate applications be tested from a
> development environment? How are Hibernate Objects
> referenced from within an application
> server?  I don't see and jndi code in any of the
> examples I have seen.
>
> Relevant Application Artifacts Follow.
>
> Many Thanks and Much Appreciation;
>
> John Olmstead
>
>
> Hibernate Facade:
>
> package ems.hibernate;
>
> import net.sf.hibernate.Session;
> import net.sf.hibernate.HibernateException;
> import net.sf.hibernate.cfg.Configuration;
> import
> com.xdocletbook.blog.exception.ApplicationException;
>
> import java.util.Collection;
> import java.util.Iterator;
>
> /**
>  * Created by IntelliJ IDEA.
>  * User: tk21104
>  * Date: Jul 28, 2004
>  * Time: 1:11:05 PM
>  * To change this template use Options | File
> Templates.
>  */
> public class EmsHibernateFacade
> {
>     private Session session = null;
>
>     public EmsHibernateFacade()
>     {
>         try
>         {
>             session = new
> Configuration().buildSessionFactory().openSession();
>         }
>         catch (HibernateException  e)
>         {
>             e.printStackTrace();
>         }
>     }
>     public static void main(String[] args )
>     {
>         EmsHibernateFacade facade = new
> EmsHibernateFacade();
>         Collection c = facade.getServers(new
> Integer(9));
>         Iterator iter = c.iterator();
>         while (iter.hasNext())
>         {
>             HibernateServer server =
> (HibernateServer)iter.next();
>
> System.out.println(server.getServerName());
>         }
>     }
>     public HibernateCompany createCompany(  String
> companyName,  String companyStatus)
>     {
>         HibernateCompany company = null;
>         try
>         {
>             company = new HibernateCompany();
>             company.setCompanyName(companyName);
>             company.setCompanyStatus(companyStatus);
>             session.save(company);
>
>         }
>         catch (HibernateException  e)
>         {
>             e.printStackTrace();
>         }
>         finally
>         {
>             return company;
>         }
>     }
>     public Collection getServers(Integer companyID)
>     {
>         HibernateCompany company = null;
>         Collection c = null;
>         try
>         {
>             company =
>
(HibernateCompany)session.load(HibernateCompany.class,
> companyID);
>             c = company.getServers();
>         }
>         catch (HibernateException  e)
>         {
>             e.printStackTrace();
>         }
>         finally
>         {
>             return c;
>         }
>     }
> }
> Sample HBM:
>
> <?xml version="1.0"?>
>
> <!DOCTYPE hibernate-mapping PUBLIC
>     "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
>
>
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd";>
>
> <hibernate-mapping>
>     <class
>         name="ems.hibernate.HibernateCompany"
>         table="HibernateCompany"
>         dynamic-update="false"
>         dynamic-insert="false"
>     >
>
>         <id
>             name="companyNumber"
>             column="companyNumber"
>             type="java.lang.Integer"
>         >
>             <generator class="uuid.Integer">
>             </generator>
>         </id>
>
>         <property
>             name="companyName"
>             type="java.lang.String"
>             update="true"
>             insert="true"
>             access="property"
>             column="companyName"
>         />
>
>         <property
>             name="companyStatus"
>             type="java.lang.String"
>             update="true"
>             insert="true"
>             access="property"
>             column="companyStatus"
>         />
>
>         <set
>             name="servers"
>             lazy="true"
>             inverse="false"
>             cascade="all"
>             sort="unsorted"
>         >
>
>               <key
>                   column="companyNumber"
>               >
>               </key>
>
>               <one-to-many
>
> class="ems.hibernate.HibernateServer"
>               />
>         </set>
>
>         <!--
>             To add non XDoclet property mappings,
> create a file named
>
=== message truncated ===




__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

---------
You may unsubscribe from this mailing list
by sending a blank email addressed to:
users-unsubscribe@xxxxxxxxxx

--
Find additional help by sending a blank email
addressed to:
users-help@xxxxxxxxxx




















<20040728192638.73129.qmail@xxxxxxxxxxxxxxxxxxxxxxx>
---------You may unsubscribe from this mailing listby sending a blank email 
addressed
to:users-unsubscribe@xxxxxxxxxxxxxxxx additional help by sending a blank 
emailaddressed
to:users-help@xxxxxxxxxx


=====
John Olmstead
jolmstead2k@xxxxxxxxx


                
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

<Prev in Thread] Current Thread [Next in Thread>