/*
* Person.java
*
* Created on 2007年8月15日, 下午10:50
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package event;
import java.util.Collection;
import java.util.Iterator;
/**
*
* @author wps20000
*/
public class Person {
private Long id;
private int age;
private String name;
private java.util.Set events = new java.util.HashSet();
/** Creates a new instance of Person */
public Person() {
}
public Person(String name)
{
this.name = name;
}
public Person(String name, int age)
{
this.name = name;
this.age = age;
}
public Long getId()
{
return id;
}
private void setId(Long id)
{
this.id = id;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public void setEvents(java.util.Set events)
{
this.events = events;
}
public java.util.Set getEvents()
{
return events;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "[url=http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd[/url]">
<hibernate-mapping>
<class name="event.Person" table="PERSONS">
<id name="id" column="PERSON_ID">
<generator class="native" />
</id>
<property name="age" type="int" />
<property name="name" type="String"/>
<set name="events" table="PERSON_EVENT">
<key cloumn="PERSON_ID"/>
<many-to-many column="EVENT_ID" class="event.Event" />
</set>
</class>
</hibernate-mapping>
package event;
import org.hibernate.Hibernate;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.HibernateException;
/**
*
* @author wps2000
*/
public class EventTest {
/** Creates a new instance of EventTest */
public EventTest() {
}
public static void main(String[] args)
{
Configuration cfg = new Configuration().addClass(Person.class).addClass(Event.class);
new SchemaExport(cfg).create(true, true);
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession();
java.util.Iterator<Object> it = session.createQuery("from Event").list().iterator();
for(;it.hasNext();)
{
System.out.println(((Event)it.next()).getTitle());
}
}
}
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource event/Person.hbm.xml
PS:jsp调用bean的时候,bean放在WEB_INF/classes/counter/目录下,但是通过 <jsp:useBean id="cnt" scope="application" class="counter.Counter" />却找不到这个bean