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.  [ 5 posts ] 
Author Message
 Post subject: problem with bulk operations
PostPosted: Thu Nov 06, 2008 9:20 am 
Newbie

Joined: Thu Nov 06, 2008 8:11 am
Posts: 3
Location: hyderabad
Hibernate version:3.1

Mapping documents: myhbconfig.xml & Employee.hbm.xml

Employee.hbm.xml
<hibernate-mapping>
<class name="EmpBean" table="Employees">
<id name="eid" type="string" column="ID" >
<generator class="assigned"/>
</id>
<property name="fname" column="FIRST_NAME" type="string" length="20" />
<property name="lname" column="LAST_NAME" type="string" length="22"/>

</class>

</hibernate-mapping>
myhbconfig.xml


<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory >
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.connection.username">HR</property>
<property name="hibernate.connection.password">HR</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.connection.autocommit">true</property>
<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>


//POJO class EmpBean.java
public class EmpBean
{
private String eid;
private String fname,lname;
public void setEid(String eid)
{ this.eid=eid; }
public void setFname(String fname)
{ this.fname=fname; }
public void setLname(String lname)
{ this.lname=lname; }
public String getEid()
{ return eid; }
public String getLname()
{ return lname; }
public String getFname()
{ return fname; }

}//class

HQLTest.java
import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;

public class HQLTest {
public static void main(String[] args) {
Session session =null;
try { SessionFactory sessionFactory = new Configuration().configure("/myhbconfig.xml").buildSessionFactory();
session = sessionFactory.openSession();
Query q=session.createQuery("select eb from EmpBean as eb");
List l=q.list();
for(int i=0;i<l.size();++i) {
EmpBean e=(EmpBean)l.get(i);
System.out.println(e.getFname()+" "+e.getLname());
}
} catch(Exception e){e.printStackTrace();
}
}
}


Full stack trace of exception that occurs:

INFO: Statistics: disabled
Nov 6, 2008 5:51:46 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Nov 6, 2008 5:51:46 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Nov 6, 2008 5:51:46 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 6, 2008 5:51:47 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Nov 6, 2008 5:51:47 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
Hibernate: select empbean0_.ID as ID, empbean0_.FIRST_NAME as FIRST2_0_, empbean0_.LAST_NAME as LAST3_0_ from Employees empbean0_
Nov 6, 2008 5:51:47 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 904, SQLState: 42000
Nov 6, 2008 5:51:47 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-00904: "EMPBEAN0_"."ID": invalid identifier

org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at HQLTest.main(HQLTest.java:19)
Caused by: java.sql.SQLException: ORA-00904: "EMPBEAN0_"."ID": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1133)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 6 more

oracle 10g:
below is the table script..
SQL> desc employees
Name Null? Type
----------------------------------------- -------- --------------

EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

****************************************************
i created a new table with employee_id number(6) --- i removed not null constrain and program went well.
Here my is question how to deal with not null constrains ? or am i going wrong?

****************************************************

_________________
If the blind lead the blind, both shall fall in a ditch


Top
 Profile  
 
 Post subject: Problem in query
PostPosted: Thu Nov 06, 2008 9:35 am 
Newbie

Joined: Thu Nov 06, 2008 9:32 am
Posts: 1
I think the query : select eb from EmpBean as eb is wrong.

select eb.edi from EmpBean as eb something i think.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 9:55 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Check you mapping document! You have:

Code:
<id name="eid" type="string" column="ID" >


but in the database:

Code:
EMPLOYEE_ID NOT NULL NUMBER(6)


The column name 'ID' in the mapping document is not found in the database. I guess you did some other changes than just removing the NOT NULL constraint to make it work.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 9:59 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Also, the datatypes doesn't match. In your mapping document you have 'string' but in the database it is 'number'.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 11:39 pm 
Newbie

Joined: Thu Nov 06, 2008 8:11 am
Posts: 3
Location: hyderabad
Thanks for all your time. It worked fine by changing the data type of bean property.

_________________
If the blind lead the blind, both shall fall in a ditch


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