Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Using Hibernate Version 2
public class QueryApp2 {
static SessionFactory sessionFactory;
public static void main ( String [ ] args ) {
try {
Configuration config = new Configuration();
sessionFactory = config.configure().addClass(Teams.class).buildSessionFactory();
Session session = null;
session = sessionFactory.openSession();
List cds = session.find("from BAM01.TEAMS");
Iterator iter = cds.iterator();
while (iter.hasNext()) {
Teams cd = (Teams)iter.next();
System.out.println(cd.getName());
}
session.flush();
session.close();
} catch( Exception x ) {
x.printStackTrace();
}
} //end main
} //end QueryApp
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/QDSN_MLB400B</property>
<property name="dialect">net.sf.hibernate.dialect.DB2400Dialect</property>
<property name="show_sql">false</property>
<mapping resource="Teams.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Teams.hbm.xml
<?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="Teams"
table="BAM01.TEAMS">
<id name="Id" type="int" unsaved-value="0">
<column name="TEAM_ID"
sql-type="int"
not-null="true"/>
<generator class="increment"/>
</id>
<property name="name">
<column name="NAME"/>
</property>
</class>
</hibernate-mapping>
Teams.java
import java.io.*;
import java.util.*;
public class Teams {
int id;
String name;
public Teams() {
}
public Teams(String name) {
this.name = name;
}
public void setId(int id) {
this.id = id;
}
public int getId(){
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
hibernate.properties
hibernate.connection.driver_class = com.ibm.as400.access.AS400JDBCDriver
hibernate.connection.url = jdbc:as400://mlb400b.mydabasename.com
hibernate.connection.username = CHENG
hibernate.connection.passord = tom6922
hibernate.dialect = net.sf.hibernate.dialect.DB2400Dialect
all these files are unber root in windows C:\
when run this standalone hibernate app iam getting the following exception.
net.sf.hibernate.MappingException: Error reading resource: Teams.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:357)
at QueryApp2.main(QueryApp2.java:42)
Caused by: net.sf.hibernate.MappingException: duplicate import: Teams
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:222)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:354)
... 1 more
Please help me, i urgently need to finish my assignment, this is just the beginning where i am stuck.
Thanks for the help.
jsp