Hi.
I simply cannot get hibernate to work properly and I'm hoping someone can help. It works fine if I use a many-to-one relationship, but many-to-many won't work. I decided to cut & paste the standard examples from the tutorial and have the same problem, so at least I know it's not the code. There must be something else I just don't get!
Any help *really* appreciated!
Maria
-------------------------------------------------------
The standard code copied from tutorial:
public class Parent {
private long id;
private Set children;
public long getId() { return id; }
private void setId(long id) { this.id=id; }
private Set getChildren() { return children; }
private void setChildren(Set children) { this.children=children; }
}
public class Child {
private long id;
private String name;
public long getId() { return id; }
private void setId(long id) { this.id=id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
-------------------------------------------------------
Hibernate mapping:
<hibernate-mapping>
<class name="net.kidzed.tests.Parent">
<id name="id">
<generator class="sequence"/>
</id>
<set role="children" lazy="true">
<key column="parent_id"/>
<one-to-many class="net.kidzed.tests.Child"/>
</set>
</class>
<class name="net.kidzed.tests.Child">
<id name="id">
<generator class="sequence"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
-------------------------------------------------------
Table creation SQL:
create table parent ( id bigint not null primary key );
create table child ( id bigint not null primary key, name varchar(255) );
create table childset ( parent_id bigint not null references parent,
child_id bigint not null references child,
primary key ( parent_id, child_id ) );
-------------------------------------------------------
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/kidzed</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<!-- mapping files -->
<mapping resource="net/kidzed/tests/Parent.hbm.xml"/>
<mapping resource="net/kidzed/model/data/Category.hbm.xml"/>
<mapping resource="net/kidzed/model/student/Student.hbm.xml"/>
<mapping resource="net/kidzed/model/user/User.hbm.xml"/>
<!--
<mapping resource="net/kidzed/model/student/PhysicalMeasurement.hbm.xml"/>
<mapping resource="net/kidzed/model/student/Observation.hbm.xml"/>
<mapping resource="net/kidzed/model/student/AcquiredKnowledgeSkill.hbm.xml"/>
-->
</session-factory>
</hibernate-configuration>
-------------------------------------------------------
The error:
INFO [main] (Environment.java:469) - Hibernate 2.1.6
INFO [main] (Environment.java:498) - hibernate.properties not found
INFO [main] (Environment.java:529) - using CGLIB reflection optimizer
INFO [main] (Configuration.java:895) - configuring from resource: /hibernate.cfg.xml
INFO [main] (Configuration.java:867) - Configuration resource: /hibernate.cfg.xml
DEBUG [main] (DTDEntityResolver.java:20) - trying to locate
http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
DEBUG [main] (DTDEntityResolver.java:29) - found
http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
DEBUG [main] (Configuration.java:853) - connection.driver_class=com.mysql.jdbc.Driver
DEBUG [main] (Configuration.java:853) - connection.url=jdbc:mysql://localhost/kidzed
DEBUG [main] (Configuration.java:853) - dialect=net.sf.hibernate.dialect.MySQLDialect
DEBUG [main] (Configuration.java:853) - show_sql=true
DEBUG [main] (Configuration.java:1012) - null<-org.dom4j.tree.DefaultAttribute@bd928a [Attribute: name resource value "net/kidzed/tests/Parent.hbm.xml"]
INFO [main] (Configuration.java:331) - Mapping resource: net/kidzed/tests/Parent.hbm.xml
DEBUG [main] (DTDEntityResolver.java:20) - trying to locate
http://hibernate.sourceforge.net/hibernate-mapping.dtd in classpath under net/sf/hibernate/
DEBUG [main] (DTDEntityResolver.java:25) -
http://hibernate.sourceforge.net/hibern ... ing.dtdnot found in classpath
INFO [main] (Binder.java:229) - Mapping class: net.kidzed.tests.Parent -> Parent
DEBUG [main] (Binder.java:486) - Mapped property: id -> id, type: long
ERROR [main] (Configuration.java:295) - Could not configure datastore from input stream
java.lang.NullPointerException
at net.sf.hibernate.util.StringHelper.qualify(StringHelper.java:241)
at net.sf.hibernate.cfg.Binder.bindCollection(Binder.java:509)
at net.sf.hibernate.cfg.Binder$2.create(Binder.java:1434)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1028)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:362)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at net.kidzed.db.HibernateUtil.<clinit>(HibernateUtil.java:28)
at net.kidzed.control.user.UserManager.findUser(UserManager.java:90)
at net.kidzed.control.user.UserManager.addUser(UserManager.java:167)
at net.kidzed.control.student.StudentManager_Test.setUp(StudentManager_Test.java:63)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
ERROR [main] (HibernateUtil.java:30) - Initial SessionFactory creation failed.
net.sf.hibernate.MappingException: Error reading resource: net/kidzed/tests/Parent.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at net.kidzed.db.HibernateUtil.<clinit>(HibernateUtil.java:28)
at net.kidzed.control.user.UserManager.findUser(UserManager.java:90)
at net.kidzed.control.user.UserManager.addUser(UserManager.java:167)
at net.kidzed.control.student.StudentManager_Test.setUp(StudentManager_Test.java:63)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: net.sf.hibernate.MappingException: java.lang.NullPointerException
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:296)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
... 20 more
Caused by: java.lang.NullPointerException
at net.sf.hibernate.util.StringHelper.qualify(StringHelper.java:241)
at net.sf.hibernate.cfg.Binder.bindCollection(Binder.java:509)
at net.sf.hibernate.cfg.Binder$2.create(Binder.java:1434)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1028)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:362)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
... 21 more