-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Question about SessionFactory
PostPosted: Mon Oct 06, 2003 11:48 pm 
Newbie

Joined: Mon Oct 06, 2003 4:18 am
Posts: 4
This is the java code:

package cathay.at.invest.data;

import java.sql.SQLException;

import cathay.at.invest.entity.InvestEmployee;
import cirrus.hibernate.Datastore;
import cirrus.hibernate.Hibernate;
import cirrus.hibernate.HibernateException;
import cirrus.hibernate.MappingException;
import cirrus.hibernate.Session;
import cirrus.hibernate.SessionFactory;

public class DataManipulate {
public static void main(String args[]){
DataManipulate dm = new DataManipulate();
int result = dm.writeToDB();
if(result == 0){
System.out.println("Insert data success !! ^__^");
}else if(result ==1){
System.out.println("sessionFactory is null +__+");
}else if(result == -1){
System.out.println("SQL Exception occur !! ?_?");
}else if(result == -2){
System.out.println("Hibernate Exception occur !! -_-");
}

}
public SessionFactory getSessionFactory(){
SessionFactory sessionFactory = null;
try{
Datastore ds = Hibernate.createDatastore();
ds.storeClass(InvestEmployee.class);
sessionFactory = ds.buildSessionFactory(); }catch(MappingException e){
throw new MappingException("can't create
sessionFactory !!"+e.getMessage());
}catch(HibernateException he){
throw new HibernateException("can't create
sessionFactory !!"+he.getMessage());
}finally{
return sessionFactory;
}
}
public int writeToDB(){
int result_code=0;
SessionFactory sf = getSessionFactory();
try {
if(sf != null){
Session session = sf.openSession();
InvestEmployee investemp = new InvestEmployee();
investemp.setEmpid("F220999695");
investemp.setEmpcode("221");
investemp.setEmpname("王小饞");
investemp.setDeptcode("61");
investemp.setZipcode("114");
investemp.setCompanytel("879369999");
investemp.setCompanyext("2111");
investemp.setCellphone("0933698756");
session.save(investemp);
session.flush();
session.connection().commit();
session.close();
}else{
result_code = 1;
}
} catch (SQLException e) {
e.printStackTrace();
result_code = -1;
} catch (HibernateException e) {
e.printStackTrace();
result_code = -2;
} finally
return result_code;
}
}

I can't get the SessionFactory, comparing to other's code it seems there is no problem? could anyone do me a favor, tell me where the problem is ?
i will be very appreciated,
thans a lot!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 10:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Are you wanting to use the 1.x version of Hibernate as opposed to the newer 2.x versions? Your code is attempting initialization of Hibernate in the 1.x manner.

Quote:
I can't get the SessionFactory

Why? Are you getting an exception? The stack trace would be far more useful than the simplistic "it does not work".


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.