-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: newbie-assistance please
PostPosted: Fri Jul 08, 2005 1:44 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Hi,

I am new to hibernate. I am getting the following exception..

og4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Error reading resource: article.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at cmp.tutorial.hibernate.FirstExample.main(FirstExample.java:19)
Caused by: org.hibernate.MappingException: org.dom4j.DocumentException: Error on line 14 of document : The element type "class" must be terminated by the matching end-tag "</class>". Nested exception: The element type "class" must be terminated by the matching end-tag "</class>".
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:403)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 7 more
Caused by: org.dom4j.DocumentException: Error on line 14 of document : The element type "class" must be terminated by the matching end-tag "</class>". Nested exception: The element type "class" must be terminated by the matching end-tag "</class>".
at org.dom4j.io.SAXReader.read(SAXReader.java:350)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:393)
... 8 more


package tutorial.hibernate;


public class Article {
private int siteID;
private int artID;




public int getSiteID() {
return siteID;
}


public int getArtID() {
return artID;
}


public void setSiteID(int string) {
siteID = string;
}


public void setArtID(int string) {
artID = string;
}


}



package cmp.tutorial.hibernate;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import java.util.ArrayList;
import java.sql.*;




public class FirstExample {
public static void main(String[] args) {
Session session = null;

// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("i am inside session");
Article article = new Article();
ArrayList arrayList = null;
String SQL_STRING = " FROM ARTICLE as article";
Query query = session.createQuery(SQL_STRING);
ArrayList list = (ArrayList)query.list();
for(int i=0; i<list.size();i++){
System.out.println(list.get(i));
}

System.out.println("Done");
session.flush();
session.close();

}

}


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Article" table="DRARTICLE">
<subselect>select * from article</subselect>
<id name="art_ID" type="long" column="ART_ID" >
<generator class="native"/>
</id>

<property name="site_ID">
<column name="SITE_ID"/>
</property>

</property>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:05 pm 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
you have put an additional </property> tag, just remove it.
It will work fine.


Top
 Profile  
 
 Post subject: But it still appears
PostPosted: Fri Jul 08, 2005 2:07 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Thanks mahikty.

I am trying to read two columns from a table. just like select siteId, articleID from a table.
Is my approach correct. Please help me!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:07 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
mahikty wrote:
you have put an additional </property> tag, just remove it.
It will work fine.


Another suggestion:

Instead of:

Code:
<property name="site_ID">
<column name="SITE_ID"/>
</property>


Why not:

Code:
<property name="site_ID" column="SITE_ID"/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:11 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Thanks for being on my side....

no luck still!!
Are my mapping and java files valid??


Top
 Profile  
 
 Post subject: THIS IS MY NEW EXCEPTION
PostPosted: Fri Jul 08, 2005 2:15 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Exception in thread "main" org.hibernate.MappingException: Error reading resource: article.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at cmp.tutorial.hibernate.FirstExample.main(FirstExample.java:19)
Caused by: org.hibernate.MappingException: class Article not found while looking for property: siteID
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:81)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:230)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:1751)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1740)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:315)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
at org.hibernate.cfg.Configuration.add(Configuration.java:358)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:395)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 7 more
Caused by: java.lang.ClassNotFoundException: Article
at java.net.URLClassLoader.findClass(URLClassLoader.java:375)
at java.lang.ClassLoader.loadClass(ClassLoader.java:562)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:442)
at java.lang.ClassLoader.loadClass(ClassLoader.java:494)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:180)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:103)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
... 16 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:19 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
I see another problem. Your property is named "site_ID" (with an underbar) but your methods are setSiteID and getSiteID (without an underbar). Try changing the property name to siteID.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:22 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
You have the same problem with art_ID. Change the property name to artID.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:23 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Thanks for your time!!

I had modified that bit of the code.

Exception is
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Error reading resource: article.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at cmp.tutorial.hibernate.FirstExample.main(FirstExample.java:19)
Caused by: org.hibernate.MappingException: class Article not found while looking for property: siteID
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:81)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:230)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:1751)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1740)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:315)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
at org.hibernate.cfg.Configuration.add(Configuration.java:358)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:395)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 7 more
Caused by: java.lang.ClassNotFoundException: Article
at java.net.URLClassLoader.findClass(URLClassLoader.java:375)
at java.lang.ClassLoader.loadClass(ClassLoader.java:562)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:442)
at java.lang.ClassLoader.loadClass(ClassLoader.java:494)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:180)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:103)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
... 16 more


MAPPING FILE IS

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Article" table="ARTICLE">
<subselect>select siteID,artID from Article</subselect>
<id name="artID" type="long" column="ART_ID" >
<generator class="native"/>
</id>

<property name="siteID" column ="SITE_ID">

</property>
</class>
</hibernate-mapping>

Java code is

package cmp.tutorial.hibernate;


public class Article {
private int siteID;
private int artID;




public int getSiteID() {
return siteID;
}


public int getArtID() {
return artID;
}


public void setSiteID(int string) {
siteID = string;
}


public void setArtID(int string) {
artID = string;
}


}


UTIL code is


package cmp.tutorial.hibernate;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import java.util.ArrayList;
import java.sql.*;




public class FirstExample {
public static void main(String[] args) {
Session session = null;

// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("i am inside session");
Article article = new Article();
ArrayList arrayList = null;
String SQL_STRING = " FROM ARTICLE as Article";
Query query = session.createQuery(SQL_STRING);
ArrayList list = (ArrayList)query.list();
for(int i=0; i<list.size();i++){
System.out.println(list.get(i));
}

System.out.println("Done");
session.flush();
session.close();

}

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:52 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
The important part of the exception is:

Code:
Caused by: org.hibernate.MappingException: class Article not found while looking for property: siteID


Your mapping file specifies:

Code:
<class name="Article" table="ARTICLE">


This is not a fully qualified classname, and this class is not in the "default" package. Try specifying the qualified class (including package) like this:

Code:
<class name="cmp.tutorial.hibernate.Article" table="ARTICLE">


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:56 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Thanks a lot my firend.. Think it helped.
I have a new exception now..

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: ARTICLE is not mapped. [ FROM ARTICLE as Article ]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:195)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
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 cmp.tutorial.hibernate.FirstExample.main(FirstExample.java:26)
Caused by: ARTICLE is not mapped.
at org.hibernate.hql.ast.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:81)
at org.hibernate.hql.ast.FromElementFactory.addFromElement(FromElementFactory.java:77)
at org.hibernate.hql.ast.FromClause.addFromElement(FromClause.java:71)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:223)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2312)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2232)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:498)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:356)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:184)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:140)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
... 7 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 3:05 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
This is a problem with SQL query:

Code:
String SQL_STRING = " FROM ARTICLE as Article";


Try this instead:

Code:
String SQL_STRING = "from Article article";


Alternatively, you can get all rows from the table using:

Code:
List articles = session.createCriteria(Article.class).list();


I prefer the Criteria API over HQL, especially for simple queries like this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 3:13 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
Thanks a lot for your reply.
But this syntax is not valid..right??

String SQL_STRING = " from Article article ";
Query query = session.createQuery(SQL_STRING);
ArrayList list = (ArrayList)query.list();
list articles = session.createCriteria(Article.class).list();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 3:23 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
looks better now..

but still issue persists..

i am inside session
Hibernate: select article0_.ART_ID as ART1_, article0_.SITE_ID as SITE2_0_ from ( select siteID,artID from Article ) article0_
Exception in thread "main" 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:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at cmp.tutorial.hibernate.FirstExample.main(FirstExample.java:26)
Caused by: java.sql.SQLException: ORA-00904: "ARTID": invalid identifier

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:241)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1477)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:677)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2311)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2554)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:452)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:382)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 6 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 3:25 pm 
Newbie

Joined: Fri Jul 08, 2005 1:41 pm
Posts: 10
looks better now..

but still issue persists..

i am inside session
Hibernate: select article0_.ART_ID as ART1_, article0_.SITE_ID as SITE2_0_ from ( select siteID,artID from Article ) article0_
Exception in thread "main" 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:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at cmp.tutorial.hibernate.FirstExample.main(FirstExample.java:26)
Caused by: java.sql.SQLException: ORA-00904: "ARTID": invalid identifier

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:241)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1477)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:677)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2311)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2554)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:452)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:382)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 6 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.