-->
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.  [ 2 posts ] 
Author Message
 Post subject: An association from the table x refers to an unmapped class
PostPosted: Thu Aug 05, 2004 2:03 am 
Newbie

Joined: Mon Aug 02, 2004 8:32 am
Posts: 16
Hibernate Version: 2.1.4

My DB SQL for ORACLE:

Code:
/*
##################### TABLE MAINGROUP ######################
*/
create table maingroup(
id_maingroup number(38) not null PRIMARY KEY,
name varchar(100) not null,
display_order number(5) not null
);

create SEQUENCE maingroup_sequence
   START WITH 1
   INCREMENT BY 1;



/*
##################### TABLE RACK ######################
*/
create table rack(
id_rack number(38) not null PRIMARY KEY,
id_maingroup number(38) not null,
name varchar(50) not null,
display_order number(5) not null,
rack_units number(5) not null,
description varchar(100),
is_dummy_rack number(1) DEFAULT 0,
constraint fk_id_maingroup foreign key (id_maingroup) references maingroup (id_maingroup)
);

create SEQUENCE rack_sequence
   START WITH 1
   INCREMENT BY 1;
/*


My Mapping doucments

File: Group.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

    <hibernate-mapping>
        <class  name="com.nokia.testbed.model.Group" table="maingroup">

            <id name="idMaingroup" type="integer" column="id_maingroup" unsaved-value="0">
                <generator class="sequence">
                    <param name="sequence">maingroup_sequence</param>
                </generator>
            </id>

            <property name="name" column="name" type="string" not-null="true"/>
            <property name="displayOrder" column="display_order" type="integer" not-null="true"/>


            <set name="racks" lazy="true">
                <key column="id_maingroup"/>
                <one-to-many class="com.nokia.testbed.model.Rack"/>
            </set>

        </class>
    </hibernate-mapping>


File: Rack.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
           "-//Hibernate/Hibernate Mapping DTD//EN"
           "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

    <hibernate-mapping>
        <class name="com.nokia.testbed.model.Rack" table="Rack">
            <id name="id" type="long" column="id_rack" unsaved-value="0">
                <generator class="increment"/>
            </id>
           <!--<property name="idMaingroup"  column="id_maingroup" type="long" not-null="true"/>-->

            <property name="name" column="name" type="string" not-null="true"/>
            <property name="displayOrder"  column="display_order" type="int" not-null="true"/>
            <property name="rackUnits"  column="rack_units"  type="int" not-null="true"/>
            <property name="description" type="string"/>
            <property name="dummyRack" column="is_dummy_rack" type="int"/>
            <many-to-one name="group" column="id_maingroup" class="com.nokia.testbed.model.Group"/>

        </class>
    </hibernate-mapping>



The java code for hibernate for creating a Rack



Code:
        ...
        Configuration cfg = new Configuration().addClass(Rack.class);
        SessionFactory sf =cfg.buildSessionFactory();
        session = sf.openSession();

        tx = session.beginTransaction();

        Group g = (Group)session.load(Group.class,new Long(idMaingroup));

        Set racks=new TreeSet();
        Rack r = new Rack();
        r.setName(name);
        r.setDisplayOrder(displayOrder);
        r.setIdMaingroup(idMaingroup);
        r.setRackUnits(rackUnits);
        r.setDescription(description);
        r.setDummyRack(dummyRack);
        racks.add(r);
        g.setRack(racks);
        session.save(r);
        session.flush();
        tx.commit();
        ......



The error Log File

2004-08-05 07:49:15,241|Thread-5|INFO |net.sf.hibernate.cfg.Environment||Hibernate 2.1.4
2004-08-05 07:49:15,249|Thread-5|INFO |net.sf.hibernate.cfg.Environment||loaded properties from resource hibernate.properties: {hibernate.c
onnection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.s
f.ehcache.hibernate.Provider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect
.OracleDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes
'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=tbadmin, hibernate.cache.region_prefix=hibernate.test, hibe
rnate.connection.url=jdbc:oracle:thin:@localhost:1521:timet, hibernate.connection.password=tbadmin, hibernate.connection.pool_size=1}
2004-08-05 07:49:15,256|Thread-5|INFO |net.sf.hibernate.cfg.Environment||using java.io streams to persist binary types
2004-08-05 07:49:15,257|Thread-5|INFO |net.sf.hibernate.cfg.Environment||using CGLIB reflection optimizer
2004-08-05 07:49:15,276|Thread-5|INFO |net.sf.hibernate.cfg.Configuration||Mapping resource: com/nokia/testbed/model/Rack.hbm.xml
2004-08-05 07:49:16,871|Thread-5|INFO |net.sf.hibernate.cfg.Binder||Mapping class: com.nokia.testbed.model.Rack -> Rack
2004-08-05 07:49:17,248|Thread-5|INFO |net.sf.hibernate.cfg.Configuration||processing one-to-many association mappings
2004-08-05 07:49:17,248|Thread-5|INFO |net.sf.hibernate.cfg.Configuration||processing one-to-one association property references
2004-08-05 07:49:17,249|Thread-5|INFO |net.sf.hibernate.cfg.Configuration||processing foreign key constraints
2004-08-05 07:49:17,442|Thread-5|WARN |org.apache.struts.action.RequestProcessor||Unhandled Exception thrown: class net.sf.hibernate.Mappin
gException


I think there is something wrong with the mapping?
But i can't fix the problem.

My associaton is one-to-many from Group to Rack and I want to create a new Rack in the Database....

Thank you for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 2:30 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
you also need to add the Group class like you did Rack, ie
Code:
Configuration cfg = new Configuration();
cfg.addClass(Rack.class);
cfg.addClass(Group.class)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.