-->
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.  [ 4 posts ] 
Author Message
 Post subject: can't fetch data from database
PostPosted: Tue Aug 09, 2005 2:22 am 
Newbie

Joined: Tue Aug 09, 2005 1:42 am
Posts: 8
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 2:47 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

it looks like you have to put antlr.jar in your classpath:

Code:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: antlr/ANT
LRException


Try antlr-2.7.5H3.jar.
It should be in your hibernate/lib directory.
There you can find a file named _README.txt
which explains what jar you need.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:22 am 
Newbie

Joined: Tue Aug 09, 2005 1:42 am
Posts: 8
Hi,

I have set classpath,but it is not working.When I am using find method then it show compilation error.
Can u explain, how named parameter is used.If i have to rewrite .hbm files for use it.

Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:23 am 
Newbie

Joined: Tue Aug 09, 2005 1:42 am
Posts: 8
Hi,

I have set classpath,but it is not working.When I am using find method then it show compilation error.
Can u explain, how named parameter is used.If i have to rewrite .hbm files for use it.

Please help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.