-->
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.  [ 6 posts ] 
Author Message
 Post subject: Using separate mapping files does not work
PostPosted: Mon Feb 28, 2005 7:27 pm 
Newbie

Joined: Mon Feb 28, 2005 7:08 pm
Posts: 4
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Using one mapping file works just fine, but splitting the subclasses into separate mapping files does not...

Hibernate version:3.0RC1

Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="example">
<class name="Person" table="person" discriminator-value="Person">
<id name="id" column="person_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<discriminator column="subtype" type="string"/>
<property name="name" column="name" type="string" length="30" not-null="true"/>
<property name="age" column="age" type="float"/>
<!--subclass name="Parent" discriminator-value="Parent">
<set name="children" inverse="false" cascade="all" lazy="true">
<key column="parent_id" />
<one-to-many class="Child"/>
</set>
</subclass-->
<!--subclass name="Child" discriminator-value="Child">
<many-to-one name="parent" class="Parent" column="parent_id" not-null="false"/>
</subclass-->
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="example">
<subclass name="Parent" extends="Person" discriminator-value="Parent">
<set name="children" inverse="false" cascade="all" lazy="true">
<key column="parent_id" />
<one-to-many class="Child"/>
</set>
</subclass>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="example">
<subclass name="Child" extends="Person" discriminator-value="Child">
<many-to-one name="parent" class="Parent" column="parent_id"
not-null="false"/>
</subclass >
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:Buildfile: C:\Documents and Settings\Peter2\workspace\HibernateTest3\build.xml
schemaexport:
[schemaexport] 00:00:07,656 INFO Environment:456 - Hibernate 3.0rc1
[schemaexport] 00:00:07,718 INFO Environment:474 - loaded properties from resource hibernate.properties: {hibernate.order_updates=true, hibernate.default_batch_fetch_size=8, hibernate.connection.driver_class=org.postgresql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=peter, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:postgresql://localhost/hibernatetest3, hibernate.show_sql=true, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
[schemaexport] 00:00:07,718 INFO Environment:501 - using java.io streams to persist binary types
[schemaexport] 00:00:07,734 INFO Environment:502 - using CGLIB reflection optimizer
[schemaexport] 00:00:07,734 INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
[schemaexport] 00:00:07,765 INFO Configuration:219 - Mapping file: C:\Documents and Settings\Peter2\workspace\HibernateTest3\src\example\child.hbm.xml
[schemaexport] 00:00:08,250 INFO Configuration:219 - Mapping file: C:\Documents and Settings\Peter2\workspace\HibernateTest3\src\example\parent.hbm.xml
[schemaexport] 00:00:08,343 INFO Configuration:219 - Mapping file: C:\Documents and Settings\Peter2\workspace\HibernateTest3\src\example\person.hbm.xml
[schemaexport] 00:00:08,421 INFO HbmBinder:256 - Mapping class: example.Person -> person
[schemaexport] 00:00:08,671 INFO Dialect:89 - Using dialect: org.hibernate.dialect.PostgreSQLDialect
[schemaexport] 00:00:08,890 INFO Configuration:844 - processing extends queue
[schemaexport] 00:00:09,046 INFO HbmBinder:733 - Mapping subclass: example.Parent -> person
[schemaexport] 00:00:09,062 INFO Configuration:848 - processing collection mappings

BUILD FAILED
C:\Documents and Settings\Peter2\workspace\HibernateTest3\build.xml:50: Schema text failed: Association references unmapped class: example.Child

Total time: 9 seconds


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 1:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how do you build the configuration ?

show that code and your cfg.xml

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 8:40 am 
Newbie

Joined: Mon Feb 28, 2005 7:08 pm
Posts: 4
The problem I had was when running the schema export tool 3.0 alpha 1. The config file isn't used there is it? Anyway, my config file and test code looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="PostgreConnectionFactory">
<property name="hibernate.connection.username">peter</property>
<property name="hibernate.connection.password">carina2004</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/hibernatetest3</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
</session-factory>
</hibernate-configuration>


package example;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Test {

public static void main(String[] args) throws Exception {
Configuration cfg = new Configuration();
cfg.addClass(Person.class);
// cfg.addClass(Parent.class); // cannot get separate mapping file to work!
// cfg.addClass(Child.class); // cannot get separate mapping file to work!
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Transaction tx = null;

try {
tx = session.beginTransaction();

Parent peter = new Parent();
peter.setName("Peter");
peter.setAge(42f);
Set<Child> children = new HashSet<Child>();

Child martin = new Child();
martin.setName("Martin");
martin.setAge(4f);
martin.setParent(peter);

Child clara = new Child();
clara.setName("Clara");
clara.setAge(1.5f);
clara.setParent(peter);

children.add(martin);
children.add(clara);
peter.setChildren(children);

// session.save(clara);
// session.save(martin);
session.save(peter);

tx.commit();

} catch (Exception e) {
if (tx != null)
tx.rollback();
throw e;
} finally {
session.close();
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 8:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok - please explain if its only in schemaexport or in your program it fails.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 4:23 pm 
Newbie

Joined: Mon Feb 28, 2005 7:08 pm
Posts: 4
The problem is that the schemaexport tool doesn't seem to handle separate mapping files. If I use one mapping file (person.hbm.xml) the code works.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 7:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use a hibernate.cfg.xml should work.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

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.