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 doucmentsFile:
Group.hbm.xmlCode:
<?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.xmlCode:
<?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 RackCode:
...
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!