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
hibernate-properties-HibernateCompany.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
hibernate.properties file:
hibernate.connection.driver_class=com.inet.tds.TdsDriver
hibernate.connection.url=jdbc:inetdae7:dbastage:1433
hibernate.connection.username=emsTest
hibernate.connection.password=emsTest
hibernate.default_schema=db2admin
hibernate.dialect=net.sf.hibernate.dialect.SybaseDialect
hibernate.show_sql=true
# The maximum number of active connections that can be allocated # from this pool at
the same
time, or zero for no limit.
hibernate.dbcp.maxActive 100
# Action to take in case of an exhausted DBCP statement pool
# ( 0 = fail, 1 = block, 2= grow)
hibernate.dbcp.whenExhaustedAction 1
hibernate.dbcp.maxWait 120000
# The maximum number of active connections that can remain
# idle in the pool, without extra ones being released, or zero
# for no limit.
hibernate.dbcp.maxIdle 10
# The SQL query that will be used to validate
# connections from this pool before returning them to the caller.
# hibernate.dbcp.validationQuery=TODO
## prepared statement cache
hibernate.dbcp.ps.maxActive 100
# Action to take in case of an exhausted DBCP statement
#pool ( 0 = fail, 1 = block, 2= grow)
hibernate.dbcp.ps.whenExhaustedAction 1
# The maximum number of milliseconds that the pool will
# wait (when there are no available connections) for a connection
# to be returned before throwing an exception, or -1 to
# wait indefinitely.
hibernate.dbcp.ps.maxWait 120000
hibernate.dbcp.ps.maxIdle 100
Sample Hibernate POJO
package ems.hibernate;
import java.util.Set;
/**
* @hibernate.class
* table="HibernateCompany"
*
*
* Author : John Olmstead
* Date: Jul 27, 2004
* Time: 8:52:02 AM
* To change this template use Options | File Templates.
*/
public class HibernateCompany
{
private Integer companyNumber;
private String companyName;
private String companyStatus;
private Set servers;
public HibernateCompany()
{}
/**
* @hibernate.id
* generator-class = "uuid.Integer"
*/
public Integer getCompanyNumber()
{
return companyNumber;
}
public void setId(Integer companyNumber) {
this.companyNumber = companyNumber;
}
/**
* @hibernate.property
*/
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
/**
* @hibernate.property
*/
public String getCompanyStatus() {
return companyStatus;
}
public void setCompanyStatus(String companyStatus) {
this.companyStatus = companyStatus;
}
/**
* @hibernate.set
* lazy="true"
* cascade="all"
*
* @hibernate.collection-one-to-many
* class="ems.hibernate.HibernateServer"
*
* @hibernate.collection-key
* column="companyNumber"
*/
public Set getServers() {
return servers;
}
public void setServers(Set servers) {
this.servers = servers;
}
}
=====
John Olmstead
[EMAIL PROTECTED]
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user