-->
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.  [ 12 posts ] 
Author Message
 Post subject: Help
PostPosted: Thu Aug 18, 2005 4:42 pm 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Hi. I'm having problem with Hibernate. I'm trying to simply load an object from a database, but I'm getting an error.

How do I enable SQL logging? The "real" way - I must say the document is rather horrible in terms of logging support. If so much effort has been put into it, why not put some effort into documenting it? All it gets is a subsection with about 5 sentences.

I've enabled show_sql in my xml file
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!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="connection.datasource">jdbc/padDS</property>
   <property name="session_factory_name">SessionFactory</property>
   <property name="dialect">org.hibernate.dialect.OracleDialect</property>
   <property name="show_sql">yes</property>
   <mapping resource="ca/gc/publiservice/boardroom/hibernate/BfBoardroom.hbm.xml" />
   <mapping resource="ca/gc/publiservice/boardroom/hibernate/BfCapability.hbm.xml" />
</session-factory>

</hibernate-configuration>


I've also copied the log4j.properties file in my classpath, but it doesn't seem to do anything. I can create my own log4j Logger using this same properties file to test it, it seems to work fine. Hibernate doesn't seem to be picking it up?

All that I can get is the stack trace printed on the screen, which is the same as the log file from Websphere with the error output.

Thanks,
Greg




Hibernate version:
3.0.5
Mapping documents:

Code between sessionFactory.openSession() and session.close():
Transaction tx = theSession.beginTransaction();

BfBoardroom ab = (BfBoardroom)theSession.get(BfBoardroom.class, new Long(6));
out.println(ab.getAddress());
theSession.close();

Full stack trace of any exception that occurs:
An exception has occurred.
org.hibernate.exception.SQLGrammarException: could not load an entity: [ca.gc.publiservice.boardroom.hibernate.BfBoardroom#6]

org.hibernate.exception.SQLGrammarException: could not load an entity: [ca.gc.publiservice.boardroom.hibernate.BfBoardroom#6] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.loadEntity(Loader.java:1359) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101) at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113) at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614) at org.apache.jsp._test._jspService(_test.java:117) at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344) at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:662) at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200) at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119) at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276) at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71) at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114) at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186) at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334) at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56) at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593) Caused by: java.sql.SQLException: ORA-00942: table or view does not exist at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272) at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181) at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420) at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896) at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2929) at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:426) 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.loadEntity(Loader.java:1345) ... 37 more
Name and version of the database you are using:
Oracle 10
The generated SQL (show_sql=true):
This is the problem!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:51 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Post your mapping files.

Your SQL debug is probably in your console log.


Top
 Profile  
 
 Post subject: Re: Help
PostPosted: Thu Aug 18, 2005 5:33 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
gcormier wrote:
How do I enable SQL logging? The "real" way - I must say the document is rather horrible in terms of logging support. If so much effort has been put into it, why not put some effort into documenting it? All it gets is a subsection with about 5 sentences.

<property name="show_sql">yes</property>


It is documented several times.
http://www.hibernate.org/hib_docs/v3/re ... n-optional
Just use the search function of your browser - you'll find it several times.

Use:
<property name="show_sql">true</property>

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:12 am 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Thank you. The SQL is now shown in the debug.

How come the debug is not going to the file like I configure it?

log4j.properties
Code:
### direct log messages to stdout ###
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.out
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=C:\\Program Files\\WebSphere\\AppServer\\installedApps\\lithium\\BoardroomFinder.ear\\boardroom.war\\boardroom.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=warn, file

log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug

### log cache activity ###
#log4j.logger.org.hibernate.cache=debug

### log transaction activity
#log4j.logger.org.hibernate.transaction=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace



This would save me from digging through Websphere logs. However, this is the SQL error

Code:
[8/19/05 8:55:49:084 EDT] 6789eeba SystemOut     O Hibernate: select bfboardroo0_.ID as ID0_, bfboardroo0_.DEPARTMENTID as DEPARTME2_0_0_, bfboardroo0_.PENDINGSTATUS as PENDINGS3_0_0_, bfboardroo0_.TITLE as TITLE0_0_, bfboardroo0_.ADDRESS as ADDRESS0_0_, bfboardroo0_.PROVINCE as PROVINCE0_0_, bfboardroo0_.CITY as CITY0_0_, bfboardroo0_.MINCAPACITY as MINCAPAC8_0_0_, bfboardroo0_.MAXCAPACITY as MAXCAPAC9_0_0_, bfboardroo0_.NOTES as NOTES0_0_, bfboardroo0_.CAPABILITY as CAPABILITY0_0_, bfboardroo0_.LASTUPDATE as LASTUPDATE0_0_, bfboardroo0_.UPDATEDBY as UPDATEDBY0_0_, bfboardroo0_.UPDATEDNOTES as UPDATED14_0_0_, bfboardroo0_.TELEPHONE1 as TELEPHONE15_0_0_, bfboardroo0_.TELEPHONE2 as TELEPHONE16_0_0_, bfboardroo0_.FAX as FAX0_0_, bfboardroo0_.EMAIL as EMAIL0_0_, bfboardroo0_.BOARDROOMID as BOARDRO19_0_0_ from BF_BOARDROOM bfboardroo0_ where bfboardroo0_.ID=?


Why is it making my table name "bfboardroo0" ? It shoudl be bf_boardroom.

Here's my BfBoardroom.hbm.xml file.


Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
                            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration.                   -->
<!-- Created Wed Aug 17 10:24:17 EDT 2005                         -->
<hibernate-mapping package="ca.gc.publiservice.boardroom.hibernate">

    <class name="BfBoardroom" table="BF_BOARDROOM">
        <id name="id" column="ID" type="java.lang.Long">
        </id>

        <property name="departmentid" column="DEPARTMENTID" type="java.lang.Long" />
        <property name="pendingstatus" column="PENDINGSTATUS" type="java.lang.Long" />
        <property name="title" column="TITLE" type="java.lang.String" />
        <property name="address" column="ADDRESS" type="java.lang.String" />
        <property name="province" column="PROVINCE" type="java.lang.Long" />
        <property name="city" column="CITY" type="java.lang.String" />
        <property name="mincapacity" column="MINCAPACITY" type="java.lang.Long" />
        <property name="maxcapacity" column="MAXCAPACITY" type="java.lang.Long" />
        <property name="notes" column="NOTES" type="java.lang.String" />
        <property name="capability" column="CAPABILITY" type="java.lang.String" />
        <property name="lastupdate" column="LASTUPDATE" type="java.util.Date" />
        <property name="updatedby" column="UPDATEDBY" type="java.lang.String" />
        <property name="updatednotes" column="UPDATEDNOTES" type="java.lang.String" />
        <property name="telephone1" column="TELEPHONE1" type="java.lang.String" />
        <property name="telephone2" column="TELEPHONE2" type="java.lang.String" />
        <property name="fax" column="FAX" type="java.lang.String" />
        <property name="email" column="EMAIL" type="java.lang.String" />

        <many-to-one name="bfBoardroom" column="BOARDROOMID" class="BfBoardroom" />

        <set name="bfBoardroom1Set" inverse="true">
            <key column="BOARDROOMID"/>
            <one-to-many class="BfBoardroom"/>
        </set>
    </class>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:22 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
gcormier wrote:
How come the debug is not going to the file like I configure it?


Try using the Java way of separating files.
Quote:
C:/Program Files/WebSphere/AppServer/installedApps/lithium/BoardroomFinder.ear/boardroom.war/boardroom.log


gcormier wrote:
[8/19/05 8:55:49:084 EDT] 6789eeba SystemOut O Hibernate: select bfboardroo0_.ID as ID0_, bfboardroo0_.DEPARTMENTID as DEPARTME2_0_0_, bfboardroo0_.PENDINGSTATUS as PENDINGS3_0_0_, bfboardroo0_.TITLE as TITLE0_0_, bfboardroo0_.ADDRESS as ADDRESS0_0_, bfboardroo0_.PROVINCE as PROVINCE0_0_, bfboardroo0_.CITY as CITY0_0_, bfboardroo0_.MINCAPACITY as MINCAPAC8_0_0_, bfboardroo0_.MAXCAPACITY as MAXCAPAC9_0_0_, bfboardroo0_.NOTES as NOTES0_0_, bfboardroo0_.CAPABILITY as CAPABILITY0_0_, bfboardroo0_.LASTUPDATE as LASTUPDATE0_0_, bfboardroo0_.UPDATEDBY as UPDATEDBY0_0_, bfboardroo0_.UPDATEDNOTES as UPDATED14_0_0_, bfboardroo0_.TELEPHONE1 as TELEPHONE15_0_0_, bfboardroo0_.TELEPHONE2 as TELEPHONE16_0_0_, bfboardroo0_.FAX as FAX0_0_, bfboardroo0_.EMAIL as EMAIL0_0_, bfboardroo0_.BOARDROOMID as BOARDRO19_0_0_ from BF_BOARDROOM bfboardroo0_ where bfboardroo0_.ID=?

Why is it making my table name "bfboardroo0" ? It shoudl be bf_boardroom.


Well, it does not. bfboardroo0_ is only a table alias which is used for accessing the table columns. The right table name is accessed in the from clause.

[...] from BF_BOARDROOM bfboardroo0_ [...]

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:28 am 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Ok.

I have an entry in the database where my ID is 6. Am I doing something wrong?

Code:
Session theSession = BoardroomFinder.getSessionFactory().openSession();
   Transaction tx = theSession.beginTransaction();
   
   BfBoardroom ab = (BfBoardroom)theSession.get(BfBoardroom.class, new Long(6));
   out.println(ab.getAddress());


Gives me

Code:
An exception has occurred.
org.hibernate.exception.SQLGrammarException: could not load an entity: [ca.gc.publiservice.boardroom.hibernate.BfBoardroom#6]

org.hibernate.exception.SQLGrammarException: could not load an entity: [ca.gc.publiservice.boardroom.hibernate.BfBoardroom#6] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.loadEntity(Loader.java:1359) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101) at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351) at
...
...
...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:43 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
gcormier wrote:
Ok.

I have an entry in the database where my ID is 6. Am I doing something wrong?

Code:
Session theSession = BoardroomFinder.getSessionFactory().openSession();
   Transaction tx = theSession.beginTransaction();
   
   BfBoardroom ab = (BfBoardroom)theSession.get(BfBoardroom.class, new Long(6));
   out.println(ab.getAddress());


Well, your code looks ok, but be aware of the difference of session.get() and session.load(). In contrast to session.load() session.get() might return NULL (if the object cannot be found) which would lead to a NullPointerException, if your object does not exist.

Are you sure your datasource is ok?
Quote:
<property name="connection.datasource">jdbc/padDS</property>

Isn't it something like:
Code:
<property name="connection.datasource">java:comp/env/jdbc/padDS</property>


I'm not so much into datasources, but check this issue.

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:07 am 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Hi Sven,

The data source is working fine. I can confirm this because I changed the datasource name to something else, and it then throws "org.hibernate.HibernateException: Could not find datasource". Changing it back fixed that.

Does my table definition affect anything?

Code:
CREATE TABLE BF_BOARDROOM (
   ID             NUMBER NOT NULL,
   BOARDROOMID    NUMBER,
   DEPARTMENTID   NUMBER,
   PENDINGSTATUS  NUMBER,
   TITLE          VARCHAR2(255),
   ADDRESS        VARCHAR2(512),
   PROVINCE       NUMBER,
   CITY           VARCHAR2(64),
   MINCAPACITY    NUMBER,
   MAXCAPACITY    NUMBER,
   NOTES          VARCHAR2(4000),
   CAPABILITY     VARCHAR2(64) DEFAULT 0,
   LASTUPDATE     DATE,
   UPDATEDBY      VARCHAR2(32),
   UPDATEDNOTES   VARCHAR2(1500),
   TELEPHONE1     VARCHAR2(40),
   TELEPHONE2     VARCHAR2(40),
   FAX            VARCHAR2(40),
   EMAIL          VARCHAR2(60));


The ID is a number, and I use the Java Long class.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:14 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Looks ok, but:

Why don't you use a primary key in your table.

Code:
CREATE TABLE BF_BOARDROOM (
...,
PRIMARY KEY  (ID)
);



Moreover, you don't use a generator class in your mapping file.
Code:
<id name="id" column="ID" type="java.lang.Long"></id>


How are you creating primary keys?
If they are assigned manually, it would look like this:
Code:
<id name="id" column="ID" type="java.lang.Long">
   <generator class="assigned"/>
</id>


See:
http://www.hibernate.org/hib_docs/v3/re ... aration-id

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:17 am 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Hi, I do have a primary key in the table, I just left that out of the definition.

Also, the generator was causing SQL errors. So I figured I'd leave that until later. The Generator affects only saving entities, not loading, right?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 9:05 am 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 1:13 pm 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Found it :|

It was pointing to the table, not the alias, so it wasn't found.

Thanks for your help,
Greg


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.