From: Boring, J. W, A. <jb...@at...> - 2002-09-30 18:15:56
|
>Nothing obviously wrong in what you have given so far.<=20 That's good news. At least I'm not totally off track! > you will have to show a bit more code than that....< here it is: public class JWBDemo { =09 private static SessionFactory sf; private static Datastore ds; private static Session myS; public static void main( String[] no_args ) throws Exception { =09 ds =3D Hibernate.createDatastore() .storeClass(Edge.class) .storeClass(Vertex.class) .storeClass(Department.class); =09 sf =3D ds.buildSessionFactory(); Session myS =3D sf.openSession(); doDept(); =09 } =09 public static void doDept() throws Exception { =09 String name =3D null; List depts =3D null; Department aDept =3D null; String Id =3D new String ("A00"); =09 try { depts =3D myS.find( "from Department in class boring.sandbox.Department" ); Iterator it =3D depts.iterator(); aDept =3D (Department) it.next(); name =3D aDept.getName(); System.out.println(aDept); } catch (Exception e){ e.printStackTrace(); }=09 } -----Original Message----- From: Gavin King [mailto:ga...@ap...] Sent: Monday, September 30, 2002 2:12 PM To: Boring, Jeff W, ALBAS; hib...@li... Subject: Re: [Hibernate] NullPointerException on Session.find Hmmmm. not sure. you will have to show a bit more code than that.... Nothing obviously wrong in what you have given so far. ----- Original Message ----- From: "Boring, Jeff W, ALBAS" <jb...@at...> To: <hib...@li...> Sent: Tuesday, October 01, 2002 3:58 AM Subject: [Hibernate] NullPointerException on Session.find > Help!!!! > > Newbie here trying some basic code and getting a nullpointer on the = find. I know it is something stupid I'm doing. Thanks for any help. > > Code is: > > depts =3D myS.find("from Department in class = boring.sandbox.Department" ); > > ---------------------- console ---------------------- > [INFO] DatastoreImpl - -Mapping resource: = cirrus/hibernate/eg/Edge.hbm.xml > [INFO] XMLHelper - -Parsing XML: unknown system id > [INFO] DatastoreImpl - -Mapping resource: cirrus/hibernate/eg/Vertex.hbm.xml > [INFO] XMLHelper - -Parsing XML: unknown system id > [INFO] Environment - -loaded properties from resource = hibernate.properties > [INFO] Environment - -echoing all SQL to stdout > [INFO] Environment - -using java.io streams to persist binary types > [INFO] Environment - -JVM proxy support: true > [WARN] Collection - -Attribute "order-by" ignored in JDK1.3 or less > [WARN] Collection - -Attribute "order-by" ignored in JDK1.3 or less > [INFO] DatastoreImpl - -Mapping resource: boring/sandbox/Department.hbm.xml > [INFO] XMLHelper - -Parsing XML: unknown system id > [INFO] Dialect - -Using dialect: class cirrus.hibernate.sql.DB2Dialect > [INFO] DriverManagerConnectionProvider - -Hibernate connection pool = size: 2 > [INFO] DriverManagerConnectionProvider - -Using driver: COM.ibm.db2.jdbc.app.DB2Driver at URL: jdbc:db2:sample > [INFO] DriverManagerConnectionProvider - -Connection properties: {user=3Dhibernate, password=3DthisIsStupid!} > [INFO] PreparedStatementCache - -prepared statement cache size: 100 > [INFO] SessionFactoryImpl - -Use outer join fetching: true > [INFO] SessionFactoryImpl - -Use scrollable result sets: true > [INFO] SessionFactoryImpl - -Use JDBC 2 batch updates: false > [WARN] SessionFactoryObjectFactory - -no JDNI name configured > [INFO] SessionFactoryImpl - -Query language substitutions: {false=3D0, no=3D'N', yes=3D'Y', true=3D1} > [INFO] SessionFactoryImpl - -Query language imports: = cirrus.hibernate.test > java.lang.NullPointerException > at boring.sandbox.JWBDemo.doDept(JWBDemo.java:50) > at boring.sandbox.JWBDemo.main(JWBDemo.java:38) > ---------------------- console ---------------------- > ---------------------- Department.java ---------------------- > package boring.sandbox; > public class Department { > private String name =3D null; > private String number =3D null; > private String location =3D null; > > public void Department(){ > } > > public String getName(){ > return name; > } > public String getNumber(){ > return number; > } > public String getLocation(){ > return location; > } > public void setName (String parm){ > name =3D parm; > } > public void setNumber (String parm){ > number =3D parm; > } > public void setLocation (String parm){ > location =3D parm; > } > } > ---------------------- Department.java ---------------------- > > ---------------------- DB Table DDL ---------------------- > CREATE TABLE "DB2ADMIN"."DEPARTMENT" ( > "DEPTNO" CHAR(3) NOT NULL , > "DEPTNAME" VARCHAR(29) NOT NULL , > "MGRNO" CHAR(6) , > "ADMRDEPT" CHAR(3) NOT NULL , > "LOCATION" CHAR(16) ) > IN "USERSPACE1" ; > > ALTER TABLE "DB2ADMIN"."DEPARTMENT" > ADD CONSTRAINT "PKEY" PRIMARY KEY > ("DEPTNO"); > ---------------------- DB Table DDL ---------------------- > > ---------------------- Department.hbn.xml ---------------------- > <?xml version=3D"1.0"?> > <!DOCTYPE hibernate-mapping PUBLIC > "-//Hibernate/Hibernate Mapping DTD//EN" > "http://hibernate.sourceforge.net/hibernate-mapping.dtd"> > > <hibernate-mapping> > > <class name=3D"boring.sandbox.Department" table=3D"department" schema=3D"db2admin"> > > <!-- comment --> > <id column=3D"DEPTNO" name=3D"number" type=3D"string"> > <generator class=3D"assigned"/> > </id> > > <property name=3D"name" column=3D"DEPTNAME" type=3D"string" /> > <property name=3D"location" column=3D"LOCATION" type=3D"string" /> > > </class> > > </hibernate-mapping> > ---------------------- Department.hbn.xml ---------------------- > > Jeff Boring > Custom & Web Services Development > AT&T Labs > jb...@at... > (813) 878-3367 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > hibernate-devel mailing list > hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel |