Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
hibernate3.x
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="newtry_test" table="newtry_test">
<id name="uname" unsaved-value="null" >
<column name="uname" sql-type="varchar(20)" not-null="true"/>
<generator class="assigned">
</generator>
</id>
<!--property name="userName"/-->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
public Test(){
//c=getContentPane();
setSize(400,400);
//c.setLayout(new BorderLayout());
//cfg=new Configuration().addClass(newtry_test.class);
SessionFactory cfg=new Configuration().configure().buildSessionFactory();
System.out.println("Configuration");
//sessionFactory=cfg.buildSessionFactory();
System.out.println("SessionFactory");
//session=sessionFactory.openSession();
session=cfg.openSession();
p1=new JPanel();
//p1.setLayout(new FlowLayout(FlowLayout.CENTER));
jtf=new JTextField(24);
jb=new JButton("Save");
p1.add(jtf);
p1.add(jb);
getContentPane().add(p1);//,BorderLayout.CENTER);
setVisible(true);
jb.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae){
Properties p=new Properties();
String username=null;
newtry_test n_t=new newtry_test(jtf.getText());
//session.save(n_t);
//System.out.println(jtf.getText());
//System.out.println(n_t.getName());
session.save(n_t);
session.flush();
//List list=session.createQuery("from newtry_test");
//List list=session.find(n_t);
try{
//Query q=session.createQuery("from newtry_test nt order by nt.uname asc");
//Query q=session.createQuery("select n_t.uname from newtry_test n_t");
//q.setFirstResult(10);
//q.setMaxResults(10);
//q.setString(0,"ggg");
//q.setParameter("uname","ggg");
//q.setProperties(n_t);
//List result = q.list();
//Iterator iter=session.createQuery("select name from newtry_test",).iterate();
//Iterator iter=result.iterator();
//Iterator iter=q.iterate();
Iterator iter=session.iterate("from newtry_test n_t");
while (iter.hasNext()) {
n_t = (newtry_test)iter.next();
System.out.println(n_t.getuname());
}
//n_t=(newtry_test)session.find("from n_t ").get(0);
System.out.println("list.");
//System.out.println(session.find("from newtry_test"));
System.out.println("Session");
//session.delete(n_t);
//tx.commit();
}catch(Exception e){
System.out.println(e);
}
System.out.println("flush");
Full stack trace of any exception that occurs:
Hibernate: insert into newtry_test (uname) values (?)
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: antlr/ANT
LRException
at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator
(ASTQueryTranslatorFactory.java:27)
at org.hibernate.impl.SessionFactoryImpl.createQueryTranslators(SessionF
actoryImpl.java:344)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.jav
a:410)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at Test.actionPerformed(Test.java:71)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Name and version of the database you are using:
Microsoft SQL server 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
log 4j