Beginner |
 |
Joined: Tue Jun 22, 2004 3:16 pm Posts: 35
|
I am new to Hibernate. I have a small test program that tries to read data from database and display it.
public class Test {
public static void main(String[] args) throws Exception{
// configuration
//Configuration cfg = new Configuration().addClass(AddressType.class);
Configuration cfg = new Configuration().addResource("AddressType.hbm.xml");
SessionFactory sft = cfg.buildSessionFactory();
// open session
Session session = sft.openSession();
// search query
String search = "select a from AddressType as a";
// search and return
Collection list = session.find(search);
for(Iterator i = list.iterator(); i.hasNext();){
AddressType addressType = (AddressType)i.next();
System.out.println("address type: " + addressType.getAddressType()
+ ", description: " + addressType.getDescription());
}
}
}
The AddressType.hbm.xml looks like this and it is in the same directory as the Test file. The AddressType.java is under the same directory too.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.bcbsma.regdomain.common.type.AddressType"
table="TBL_ADDRTYPE">
<id name="addressType" type="string"
unsaved-value="null">
<column name="ADDRTYPE" sql-type="VARCHAR2(1)"
not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="description">
<column name="DESCRIPTION" sql-type="VARCHAR2(20)"
not-null="false"/>
</property>
</class>
</hibernate-mapping>
Any thing wrong?
Thanks,
jw
|
|