-->
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.  [ 1 post ] 
Author Message
 Post subject: BUG with joined-subclass with non-pk id property?
PostPosted: Thu May 29, 2008 11:10 am 
Newbie

Joined: Tue Feb 05, 2008 12:48 pm
Posts: 2
Hi

Loading an instance of a joined subclass after querying like this:


(NB this code assumes there is a SaleOrder with id=2, orderId=1)

Code:
Query q = session.createQuery( "FROM SaleOrder WHERE id=2 ");
      
SaleOrder s = ( SaleOrder ) q.iterate().next();

s.getId();


causes ObjectNotFoundException. The query generates the correct sql and returns a proxy but when getId() is called it gives exception shown below.

Exact same setup worked in hibernate 2. Hibernate appears to be treating id as the pk property.

If I rename id property to idd it works. Also If I use session.get() it returns a proxy (and works) or query.uniqueResult() (no proxy) it works.

From the docs:

"The special property (lowercase) id may be used to reference the identifier property of an entity provided that entity does not define a non-identifier property named id."

Am I doing something wrong?

Thanks,

Dominic.


Hibernate version:

version 3.2.5 (2007.07.31)

Mapping documents:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="test.Order"
table="orders"
proxy="test.Order"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="orderId"
column="order_id"
type="java.lang.Integer"
>
<generator class="identity">
</generator>
</id>

<joined-subclass
name="test.SaleOrder"
table="sale_orders"
dynamic-update="false"
dynamic-insert="false"
proxy="test.SaleOrder"
>
<key
column="order_id"
/>

<property
name="id"
type="java.lang.Integer"
update="false"
insert="false"
access="property"
>
<column
name="idd"
not-null="true"
sql-type="INT"
/>
</property>

</joined-subclass>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Query q = session.createQuery( "FROM SaleOrder WHERE id=2 ");

SaleOrder s = ( SaleOrder ) q.iterate().next();

s.getId()

Full stack trace of any exception that occurs:

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [test.SaleOrder#2]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:68)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at test.SaleOrder$$EnhancerByCGLIB$$e6914948.getId(<generated>)
at test.Test.testLoadSaleOrderByIdViaProxy(Test.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Name and version of the database you are using:

MSSQL 2000

The generated SQL (show_sql=true):

select saleorder0_.idd as col_0_0_ from sale_orders saleorder0_ inner join orders saleorder0_1_ on saleorder0_.order_id=saleorder0_1_.order_id where saleorder0_.idd=2

select saleorder0_.order_id as order1_4_0_, saleorder0_.idd as idd5_0_ from sale_orders saleorder0_ inner join orders saleorder0_1_ on saleorder0_.order_id=saleorder0_1_.order_id where saleorder0_.order_id=?


Debug level Hibernate log excerpt:

on request


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.