wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes facing problem while inserting record with dynamic  class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "facing problem while inserting record with dynamic  class " Watch "facing problem while inserting record with dynamic  class " New topic
Author

facing problem while inserting record with dynamic class

anish reddy
Ranch Hand

Joined: Apr 19, 2008
Posts: 74
my code is
<?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>
<class name="address" table="address" dynamic-insert="true">
<id name="code">
<generator class="assigned"/>
</id>



<dynamic-component name="houseAddress" insert="true">
<property name="name" column="name" type="string"/>
<property name="pin" column="pin" type="int"/>
</dynamic-component>

</class>
</hibernate-mapping>

package org.an;

import java.util.HashMap;
import java.util.Map;

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

public class MainComponent {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
org.hibernate.cfg.Configuration lConfiguration=null;

SessionFactory lSessionFactory=null;
Session lSession=null;
org.hibernate.Transaction lTransaction=null;

lConfiguration=new Configuration();
lConfiguration.setProperty("hibernate.dialect","org.hibernate.dialect.OracleDialect");
lConfiguration.setProperty("hibernate.connection.driver_class","oracle.jdbc.driver.OracleDriver");
lConfiguration.setProperty("hibernate.connection.url","jdbcracleci:@XE");
lConfiguration.setProperty("hibernate.connection.username","system");
lConfiguration.setProperty("hibernate.connection.password","manager");
//<property name="hibernate.hbm2ddl.auto">update</property>
lConfiguration.setProperty("hibernate.hbm2ddl.auto","update");

lConfiguration.setProperty("show_sql","true");
lConfiguration.addResource("sample.hbm.xml");
try{
lSessionFactory=lConfiguration.buildSessionFactory();
lSession=lSessionFactory.openSession();
lTransaction=lSession.beginTransaction();
Map address=new HashMap();
address.put("code",454);


Map houseAddress=new HashMap();
houseAddress.put("name","ANI");
houseAddress.put("pin",676);
address.put("houseAddress",houseAddress);


lSession.persist(address);
lTransaction.commit();


System.out.println("inserted");

}
finally
{
if(lSession!=null&&lSession.isOpen())
{lSession.close();

}
if(lSessionFactory!=null)
{
lSessionFactory.close();
}
}


}

}
iam getting exception


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Error reading resource: sample.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.an.MainComponent.main(MainComponent.java:34)
Caused by: org.hibernate.MappingException: class address not found while looking for property: code
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:81)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:230)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:357)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:291)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
at org.hibernate.cfg.Configuration.add(Configuration.java:358)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:395)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 1 more
Caused by: java.lang.ClassNotFoundException: address
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:103)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
... 9 more
help me to solve this
 
 
subject: facing problem while inserting record with dynamic class
 
Similar Threads
InvalidMappingException
hibernate hello world
org.hibernate.InvalidMappingException: Could not parse mapping document from resource customercare.h
Hibernate - field not found: id
Could not read mappings from resource ?