-->
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.  [ 4 posts ] 
Author Message
 Post subject: Loading subclass of an abstract class - FAILS
PostPosted: Fri Jun 24, 2005 3:50 pm 
Newbie

Joined: Fri Jun 24, 2005 3:32 pm
Posts: 11
Hey all! I'm new to Hibernate, so I'm hoping this is an easy one. Unfortunately, all my searches have come up null.

I've got an abstract class, and a subclass managed by hibernate:

Code:
Request (Abstract)
     |
     ------- Ticket


They are setup using table-per-subclass WITHOUT a discriminator. I can create and save tickets just fine. But I cannot load any of them.

Code:
Ticket ticket = (Ticket) session.get(Ticket.class,new Long(1));


The SQL output'd from hibernate works just fine. When I use it in my DB, it comes back with the correct data, but Hibernate returns 'null'. Using the SQL, I do have the id=1 in my table.

Here is my exception using session.load():

Quote:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [core.Ticket#1]




What could I be doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 7:23 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
It might be an easy fix, but without some details its really hard to tell. Post the related parts of your Hibernate XML file and DB schema/data. :)


Top
 Profile  
 
 Post subject: More INFO:
PostPosted: Mon Jun 27, 2005 10:50 am 
Newbie

Joined: Fri Jun 24, 2005 3:32 pm
Posts: 11
Okay. Here is my hibernate mapping file. I'm just keeping it simple for now:

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

<hibernate-mapping package="core">
   <class name="core.Request"
         table="REQUESTS">
         
         <id name="id"
               column="REQ_ID"
               type="long">
               <generator class="native"/>
         </id>
         
         <property name="created"/>
      

         <joined-subclass name="core.Ticket"
                      table = "TICKET" >
               <key column = "TICKET_ID" />
               
               <property name="state" />
               <property name="problem" />
               <property name="resolution" />
         </joined-subclass>
         
   </class>
</hibernate-mapping>


And for the database schema:

Code:
create table REQUESTS (
   REQ_ID bigint not null auto_increment,
   created datetime,
   primary key (REQ_ID)
)

create table TICKET (
   TICKET_ID bigint not null,
   state varchar(255),
   problem varchar(255),
   resolution varchar(255),
   primary key (TICKET_ID)
)

alter table TICKET add index FK937B5F0C1B50D64E (TICKET_ID), add constraint FK937B5F0C1B50D64E foreign key (TICKET_ID) references REQUESTS (REQ_ID)


This is the schema generated by hibernate using SchemaExport.create()

This is really bugging me. I can iterate through all the Tickets (subclass). And once I iterate through them, I can load each one up using the session.load(classname,id) (since it's grabbing it from cached information), but I can't load them up directly, if they aren't in cache.

I've been troubleshooting this all weekend.


Top
 Profile  
 
 Post subject: Debug messages
PostPosted: Mon Jun 27, 2005 12:08 pm 
Newbie

Joined: Fri Jun 24, 2005 3:32 pm
Posts: 11
Here are the messages from the console when running

Ticket ticket2 = (Ticket) session.load(Ticket.class,new Long(2));

As stated in the debug messages, its binding '2' to parameter: 1. When I use the SQL in my DB, it comes back with the proper join and a single row.

Code:
Hibernate: select ticket0_.TICKET_ID as REQ1_0_, ticket0_1_.created as created0_0_, ticket0_.state as state1_0_, ticket0_.problem as problem1_0_, ticket0_.resolution as resolution1_0_ from TICKET ticket0_ inner join REQUESTS ticket0_1_ on ticket0_.TICKET_ID=ticket0_1_.REQ_ID where ticket0_.TICKET_ID=?
12:02:15,066 DEBUG AbstractBatcher:365 - preparing statement
12:02:15,206 DEBUG LongType:59 - binding '2' to parameter: 1
12:02:15,206 DEBUG AbstractBatcher:293 - about to open ResultSet (open ResultSets: 0, globally: 0)
12:02:15,206 DEBUG Loader:388 - processing result set
12:02:15,206 DEBUG Loader:412 - done processing result set (0 rows)
12:02:15,206 DEBUG AbstractBatcher:300 - about to close ResultSet (open ResultSets: 1, globally: 1)
12:02:15,206 DEBUG AbstractBatcher:285 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
12:02:15,216 DEBUG AbstractBatcher:403 - closing statement
12:02:15,216 DEBUG Loader:508 - total objects hydrated: 0
12:02:15,216 DEBUG PersistenceContext:789 - initializing non-lazy collections
12:02:15,216 DEBUG Loader:1335 - done entity load
12:02:15,226  INFO DefaultLoadEventListener:85 - Error performing load command
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [core.Ticket#2]


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