2。UserType
import java.io.Serializable;/**
 * @Hibernate.class table="P_USERTYPE"
 */
public class UserType 
implements Serializable{

private static final long serialVersionUID=1;

public Long id;
public String value;
public String memo;


public UserType() {
super();
// TODO Auto-generated constructor stub
}

public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}

public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}

解决方案 »

  1.   

    3。HibernateTest
    import java.io.*;
    import junit.framework.TestCase;
    import org.hibernate.*;
    import org.hibernate.cfg.*;
    import com.mdc.data.beans.user.*;
    public class HibernateTest extends TestCase {

    Session session = null;

    protected void setUp(){
    try {
    File file = new File("Hibernate.cfb.xml");
    Configuration config = new Configuration().configure(file);
    SessionFactory sessionFactory =
    config.buildSessionFactory();
    session = sessionFactory.openSession();
    }
    catch (HibernateException e) {
    e.printStackTrace();
    }
    }

    protected void tearDown(){
    try {
    session.close();
    System.out.println("close");
    } catch (HibernateException e) {
    e.printStackTrace();
    }
    }

    public void testInsert(){
    try {
    UserType userType=new UserType();
    userType.setMemo("");
    userType.setValue("测试spring2");
    session.save(userType);
    session.flush();
    System.out.println(userType.getId());
    }
    catch (HibernateException e) {
    e.printStackTrace();
    }
    catch(Exception e){
    e.printStackTrace();
    }
    }


    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }}