-->
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: Using joined-subclass, and inheritance - Help -
PostPosted: Tue Apr 06, 2004 2:34 pm 
Newbie

Joined: Tue Apr 06, 2004 2:01 pm
Posts: 4
I am trying to write a sample app that uses the joined-subclass feature in hibernate. I am using the Payment sample from the documentation.

Here is the declaration:
<?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
package="com.myorg.pay">
<class name="Payment" table="PAYMENT">
<id name="id">
<generator class="native"/>
</id>
<property name="code" column="CODE"/>

<joined-subclass name="CreditPayment" table="CREDIT_PAYMENT">
<key column="ID"/>
<property name="account" column="ACCOUNT"/>
</joined-subclass>
</class>
</hibernate-mapping>

DB has two tables:
1. Payment with (id, code)
2. Credit_Payment with (id, account)


CODE TO ACCESS CLASSES:
Query payments = session.createQuery("select pay from Payment as pay ");
for (Iterator it = payments.iterate(); it.hasNext();) {
Payment view = (Payment) it.next();
System.out.println("ID: "+view.getId());
}

ERROR:
Hibernate: select payment0_.id as id0_, case when payment0__1_.ID is not null then 1 when payment0_.id is not null then 0 end as clazz_0_, payment0_.CODE as CODE3_0_, payment0__1_.ACCOUNT as ACCOUNT4_0_ from PAYMENT payment0_ left outer join CREDIT_PAYMENT payment0__1_ on payment0_.id=payment0__1_.ID where payment0_.id=?
net.sf.hibernate.JDBCException: could not load by id: [com.myorg.pay.Payment#1]

I haven


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 6:05 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what happens if you try the same query without
Code:
<joined-subclass name="CreditPayment" table="CREDIT_PAYMENT">
<key column="ID"/>
<property name="account" column="ACCOUNT"/>
</joined-subclass>

???

I'm working with joined suclasses too and it works great.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 9:24 am 
Newbie

Joined: Tue Apr 06, 2004 2:01 pm
Posts: 4
If I remove the joined-subclass declaration, everything works great. I am able to retrieve data using find, iterate, load, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 9:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Next time you post, take the time to just glance at the huge red message which explains the things we expect you to provide.

Something about "full stack trace", for example.

Otherwise, you just waste our time.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 11:19 am 
Newbie

Joined: Tue Apr 06, 2004 2:01 pm
Posts: 4
My appologies,

Hibernate Version: Hibernate 2.1.2
Database: Oracle 8i
Mapping:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.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:@10.105.23.52:1521:EMS2</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test</property>
<property name="dialect">net.sf.hibernate.dialect.OracleSQLDialect</property>
<property name="show_sql">true</property>

<!-- Mapping files -->
<mapping resource="Payment.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Error:
Hibernate: select payment0_.ID as x0_0_ from PAYMENT payment0_
Hibernate: select payment0_.ID as ID0_, case when payment0__1_.ID is not null then 1 when payment0_.ID is not null then 0 end as clazz_0_, payment0_.CODE as CODE0_0_, payment0__1_.ACCOUNT as ACCOUNT1_0_ from PAYMENT payment0_ left outer join CREDIT_PAYMENT payment0__1_ on payment0_.ID=payment0__1_.ID where payment0_.ID=?

net.sf.hibernate.JDBCException: could not load by id: [com.myorg.pay.Payment#1]
at net.sf.hibernate.persister.NormalizedEntityPersister.load(NormalizedEntityPersister.java:413)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2081)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1955)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1917)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215)
at net.sf.hibernate.type.EntityType.nullSafeGet(EntityType.java:154)
at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:71)
at net.sf.hibernate.impl.IteratorImpl.<init>(IteratorImpl.java:48)
at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:849)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1577)
at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)
at com.myorg.pay.Main.main(Main.java:79)

Caused by: java.sql.SQLException: ORA-00933: SQL command not properly ended
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:831)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2496)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2840)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.NormalizedEntityPersister.load(NormalizedEntityPersister.java:405)
... 12 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 11:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
net.sf.hibernate.dialect.OracleSQLDialect


What is this?? You should be using net.sf.hibernate.dialect.OracleDialect


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 12:22 pm 
Newbie

Joined: Tue Apr 06, 2004 2:01 pm
Posts: 4
After changing the dialect to net.sf.hibernate.dialect.OracleDialect everything is working great.

Thanks for all the help.


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.