thank you for your response.
I finally succeeded to get over the problem, but after that, after executing the main method "Exec.java", there is a problem as follows:
5 31, 2012 4:44:38 午後 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.3.Final}
5 31, 2012 4:44:38 午後 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
5 31, 2012 4:44:38 午後 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
5 31, 2012 4:44:39 午後 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
5 31, 2012 4:44:39 午後 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
5 31, 2012 4:44:39 午後 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
/hibernate.cfg.xml not foundExec.java
Code:
package com.xecys.ORMapper;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class Exec {
public static void main(String[] args) {
Exec ex = new Exec();
ex.Execute();
}
public void Execute(){
Session session = null;
try{
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(serviceRegistry);
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact con = new Contact() ; //MUMIN_VILLAGE mapping
con.setAddress("123");
con.setFirstName("567");
session.save(con);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
// Actual contact insertion will happen at this step
}
// session.flush();
// session.close();
}
}
hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!--Oracle JDBC Driver connection -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@foo.bar.foo.bar :1521:ORCL</property>
<property name="connection.username">k</property>
<property name="connection.password">sano</property>
<property name="connection.pool_size">1</property>
<!-- <property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<!-- Mapping files 作り方 -->
<!-- <mapping class="entity.Employee"/> -->
<mapping class="com.xecys.ORMapper.EMP" />
<!-- <mapping resource="/AdressFeatHibernate/src/hibernate.cfg.xml"/> -->
<!-- <EMP.hbm.xml = "C:\Users\keisugano\XecysManager\AdressFeatHibernate\EMP.hbm.xml"/> -->
</session-factory>
</hibernate-configuration>
EMP.hbm.xml
Code:
<?xml version="1.0" encoding='utf-8' ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.xecys.ORMapper.EMP" table="MUMIN_VILLAGE">
// what is class name?
<generator class="assigned" />
<property name="FIRSTNAME" type="text" column="FIRSTNAME" />
<property name="LASTNAME" type="text" column="LASTNAME" />
<property name="ADDRESS" type="text" column="ADDRESS" />
<property name="PHONE" type="text" column="PHONE" />
<property name="EMAIL" type="text" column="EMAIL" />
</class>
</hibernate-mapping>
contact.hbm.xml
Code:
<?xml version="1.0"? encoding='utf-8' >
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.xecys.ORMapper.Contact" table="MUMIN_VILLAGE">
<id name="FIRSTNAME" type="text" column="FIRSTNAME" >
<id name="LASTNAME" type="text" column="LASTNAME" >
<id name="PHONE" type="text" column="PHONE" >
<id name="EMAIL" type="text" column="EMAIL" >
<generator class="assigned"/>
</id>
<property name="FIRSTNAME">
<column name="FIRSTNAME" />
</property>
<property name="LASTNAME">
<column name="LASTNAME" />
</property>
<property name="PHONE">
<column name="PHONE"/>
</property>
<property name="EMAIL">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
Build.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.6.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@foo.bar.foo.bar:1521:ORCL</property>
<property name="hibernate.connection.username">i</property>
<property name="hibernate.connection.password">no</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="/AdressFeatHibernate/src/com/xecys/ORMapper/EMP.hbm.xml"/>
<mapping resource="/AdressFeatHibernate/src/com/xecys/ORMapper/hibernate.cfg.xml"/>
</session-factory>
</hibernate-configuration>
Is anything wrong with these codes? Actually I decided to put utf description in each of the xml tags....
Also, I have to show the Package Explorer...
[img]
http://2.bp.blogspot.com/-tAx8akAU2OU/T8cmjkPeDVI/AAAAAAAACcg/jUsG2bbRgKA/s1600/bandicam%2B2012-05-31%2B17-04-27-890.jpg[/img]