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.  [ 7 posts ] 
Author Message
 Post subject: java.lang.RuntimeException: Could not execute query
PostPosted: Tue Oct 26, 2004 3:39 pm 
Newbie

Joined: Tue Oct 26, 2004 10:29 am
Posts: 6
Here is my very simple method.... Why do I get this error?

Hibernate: select from
java.lang.RuntimeException: Could not execute query
at gsptech.autopay.biz.EventManager.get(EventManager.java:75)
at gsptech.autopay.biz.EventManager.main(EventManager.java:29)
Exception in thread "main"


private List get() {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

List result = session.find("from AWB2");

tx.commit();
session.close();

return result;
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage());
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 4:20 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
please post the StackTrace of the Hibernate-Exception ... perhaps there are some more information about it ...
And perhaps a Mapping ...

Is 'AWB2' your tableName oder the ClassName defined in the mapping file?! ..

A bit more information would be helpfull ;)

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:05 am 
Newbie

Joined: Tue Oct 26, 2004 10:29 am
Posts: 6
That was my whole stack trace :(

Initializing Hibernate
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Finished Initializing Hibernate
Hibernate: select myawb0_.TRACKING_NBR as TRACKING1_0_, myawb0_.SHIP_TMSP as SHIP_TMSP0_, myawb0_.ORIGINATION_LOC_CD as ORIGINAT3_0_, myawb0_.DOC_NONDOC_FLG as DOC_NOND4_0_, myawb0_.DIM_WEIGHT_NBR as DIM_WEIG5_0_, myawb0_.PACKAGE_RECIPIENT_NM as PACKAGE_6_0_ from AWB myawb0_ where myawb0_.TRACKING_NBR=?
QQQ: null
Hibernate: update AWB set SHIP_TMSP=?, ORIGINATION_LOC_CD=?, DOC_NONDOC_FLG=?, DIM_WEIGHT_NBR=?, PACKAGE_RECIPIENT_NM=? where TRACKING_NBR=?
Hibernate: select from
java.lang.RuntimeException: Could not execute query
at gsptech.autopay.biz.EventManager.get(EventManager.java:83)
at gsptech.autopay.biz.EventManager.main(EventManager.java:32)

----------------------------------------------------------



The table is now AWB. The class is MyAWB

------------------------------------------------------------------------------------------

package gsptech.autopay.biz;

import java.sql.Timestamp;
import java.util.List;

import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;

public class EventManager {

private SessionFactory sessionFactory;

public EventManager() {
try {
System.out.println("Initializing Hibernate");
sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Finished Initializing Hibernate");
} catch (HibernateException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
EventManager instance = new EventManager();

instance.store();


List awbs = instance.get();
for (int i = 0; i<awbs.size(); i++) {
AWB awb = (AWB) awbs.get(i);

System.out.println(awb.getDimWeight());
System.out.println(awb.getTrackingNumber());
System.out.println(awb.getShipTimestamp());
System.out.println(awb.getRecipient());
System.out.println(awb.getOriginationLocID());
System.out.println(awb.getDocNonDocFlag());

}

System.exit(0);
}

private void store() {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

MyAWB awb = new MyAWB();
awb.setDimWeight(new Double(8.0));
awb.setTrackingNumber("87773456789");
awb.setShipTimestamp(new Timestamp(1111111111));
awb.setRecipient("Anthony K. Smith");
awb.setOriginationLocID("ABCDE");
//awb.setDocNonDocFlag(new Character('N'));

awb = (MyAWB) session.saveOrUpdateCopy(awb);
System.out.println("QQQ: " + awb.getDocNonDocFlag());

tx.commit();
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}

private List get() {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

List result = session.find("from AWB");

tx.commit();
session.close();

return result;
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage());
}
}

}
--------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="gsptech.autopay.biz.MyAWB" table="AWB">

<id name="trackingNumber" type="string" column="TRACKING_NBR" length="12">
<generator class="assigned"/>
</id>

<!--
<id name="id" type="long" column="UID_NBR" >
<generator class="increment"/>
</id>
-->
<!-- <property name="trackingNumber" column="TRACKING_NBR" type="string" length="12" /> -->
<property name="shipTimestamp" column="SHIP_TMSP" type="timestamp" />
<property name="originationLocID" column="ORIGINATION_LOC_CD" type="string" length="5" />
<property name="docNonDocFlag" column="DOC_NONDOC_FLG" type="character" />
<property name="dimWeight" column="DIM_WEIGHT_NBR" type="double" />
<property name="recipient" column="PACKAGE_RECIPIENT_NM" type="string" length="50" />
</class>
</hibernate-mapping>

-----------------------------------------------------------
package gsptech.autopay.biz;

import java.sql.Timestamp;
import java.util.List;

import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;

public class EventManager {

private SessionFactory sessionFactory;

public EventManager() {
try {
System.out.println("Initializing Hibernate");
sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Finished Initializing Hibernate");
} catch (HibernateException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
EventManager instance = new EventManager();

instance.store();


List awbs = instance.get();
for (int i = 0; i<awbs.size(); i++) {
AWB awb = (AWB) awbs.get(i);

System.out.println(awb.getDimWeight());
System.out.println(awb.getTrackingNumber());
System.out.println(awb.getShipTimestamp());
System.out.println(awb.getRecipient());
System.out.println(awb.getOriginationLocID());
System.out.println(awb.getDocNonDocFlag());

}

System.exit(0);
}

private void store() {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

MyAWB awb = new MyAWB();
awb.setDimWeight(new Double(8.0));
awb.setTrackingNumber("87773456789");
awb.setShipTimestamp(new Timestamp(1111111111));
awb.setRecipient("Anthony K. Smith");
awb.setOriginationLocID("ABCDE");
//awb.setDocNonDocFlag(new Character('N'));

awb = (MyAWB) session.saveOrUpdateCopy(awb);
System.out.println("QQQ: " + awb.getDocNonDocFlag());

tx.commit();
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}

private List get() {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

List result = session.find("from AWB");

tx.commit();
session.close();

return result;
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage());
}
}

}

-------------------------------------------------------------------------
/*
* Created on Oct 11, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package gsptech.autopay.biz;


import java.io.*;
import java.sql.*;

/**
* @author as411161
*
* This object holds all of the information that AutoPay needs for an inbound
* awb.
*/
public class MyAWB implements Serializable{

long id;
private String trackingNumber;
private Timestamp shipTimestamp;
private String originationLocID;
private Character docNonDocFlag;
private Double dimWeight;
private String recipient;


/**
* @return Returns the originationLocID.
*/
public String getOriginationLocID() {
return originationLocID;
}
/**
* @param originationLocID
* The originationLocID to set.
*/
public void setOriginationLocID(String originationLocID) {
this.originationLocID = originationLocID;
}

/**
* @return Returns the recipient.
*/
public String getRecipient() {
return recipient;
}
/**
* @param recipient
* The recipient to set.
*/
public void setRecipient(String recipient) {
this.recipient = recipient;
}

/**
* @return Returns the shipTimestamp.
*/
public Timestamp getShipTimestamp() {
return shipTimestamp;
}
/**
* @param shipTimestamp
* The shipTimestamp to set.
*/
public void setShipTimestamp(Timestamp shipTimestamp) {
this.shipTimestamp = shipTimestamp;
}

/**
* @return Returns the trackingNumber.
*/
public String getTrackingNumber() {
return trackingNumber;
}
/**
* @param trackingNumber
* The trackingNumber to set.
*/
public void setTrackingNumber(String trackingNumber) {
this.trackingNumber = trackingNumber;
}
/**
* @return Returns the dimWeight.
*/
public Double getDimWeight() {
return dimWeight;
}
/**
* @param dimWeight
* The dimWeight to set.
*/
public void setDimWeight(Double dimWeight) {
this.dimWeight = dimWeight;
}
/**
* @return Returns the docNonDocFlag.
*/
public Character getDocNonDocFlag() {
return docNonDocFlag;
}
/**
* @param docNonDocFlag
* The docNonDocFlag to set.
*/
public void setDocNonDocFlag(Character docNonDocFlag) {
this.docNonDocFlag = docNonDocFlag;
}

/**
* @return Returns the id.
*/
public long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(long id) {
this.id = id;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:15 am 
Newbie

Joined: Tue Oct 26, 2004 10:29 am
Posts: 6
Oh it says, missing expresion. But how do I fix?


Initializing Hibernate
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Finished Initializing Hibernate
Hibernate: select myawb0_.TRACKING_NBR as TRACKING1_0_, myawb0_.SHIP_TMSP as SHIP_TMSP0_, myawb0_.ORIGINATION_LOC_CD as ORIGINAT3_0_, myawb0_.DOC_NONDOC_FLG as DOC_NOND4_0_, myawb0_.DIM_WEIGHT_NBR as DIM_WEIG5_0_, myawb0_.PACKAGE_RECIPIENT_NM as PACKAGE_6_0_ from AWB myawb0_ where myawb0_.TRACKING_NBR=?
QQQ: null
Hibernate: update AWB set SHIP_TMSP=?, ORIGINATION_LOC_CD=?, DOC_NONDOC_FLG=?, DIM_WEIGHT_NBR=?, PACKAGE_RECIPIENT_NM=? where TRACKING_NBR=?
Hibernate: select from
net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1547)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
at gsptech.autopay.biz.EventManager.get(EventManager.java:80)
at gsptech.autopay.biz.EventManager.main(EventManager.java:32)
Caused by: java.sql.SQLException: ORA-00936: missing expression

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:643)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:1674)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1870)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:314)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
... 4 more
java.lang.NullPointerException
at gsptech.autopay.biz.EventManager.main(EventManager.java:33)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:16 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi,

you call the 'find'-method with your tableName:
Code:
List result = session.find("from AWB");


Try it with the name of the Java-Class:
Code:
List result = session.find("from MyAWB");


Hibernate does the mapping ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:21 am 
Newbie

Joined: Tue Oct 26, 2004 10:29 am
Posts: 6
That did it. Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:23 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
no problem :) i've done the same during my first steps with hibernate ;)

gtx
curio


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