-->
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: Beginner Problem (propbably a loading problem)
PostPosted: Tue Mar 13, 2007 5:14 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Hi

I created my first entity with some value-types (as component-element within a list-mapping).

A short overview of my domain model:
Code:
public class Vehicle { <-- this is my entity
   ... some attributes
   List <Part> parts <-- this is mapped as component-element

   ..getter and setter
}


Now I am facing a strange problem when callin aVehicle.getParts().
The Debugger jumps to my Vehicle-Object and I can see that my list contains several parts, but te result of the call getParts gives me a PersistentList which is empty?

Can someone explain this to me and what I have to do?

Thanks in advance
-- Marc

EDIT: maybe its a good idea to add my vehicle.hbm.xml
Code:
<hibernate-mapping package="toolseye.datastructures.vehiclemanagement">
   
   <typedef name="tiaExaminationType" class="toolseye.hibernatewrapper.usertypes.StringEnumUserType">
      <param name="enumClassname">toolseye.datastructures.vehiclemanagement.enums.TiaExaminationType</param>
   </typedef>

   <class name="Vehicle" table="VEHICLES">
        <id name="id" column="VEHICLE_ID">
            <generator class="native"/>
        </id>
        <property name="vin" not-null="true"/>
        <property name="type" not-null="true"/>
        <property name="manufacturer" not-null="true"/>
        <property name="category"/>
        <property name="year_of_manufacture"/>
       
        ...
       
        <list name="parts" table="VEHICLE_PARTS">
           <key column="VEHICLE_ID"/>
           <list-index column="POSITION"/>
           <composite-element class="Part">
              <property name="name"/>
              <property name="description"/>
              <property name="distance"/>
              <property name="date" type="timestamp" column="PART_DATE"/>
           </composite-element>
        </list>
       
        ...
    </class>


Top
 Profile  
 
 Post subject: Lazy loading problem?
PostPosted: Tue Mar 13, 2007 8:37 pm 
Newbie

Joined: Sat May 13, 2006 12:00 pm
Posts: 19
Try adding 'lazy="false"' as an attribute on the <list> element in your .hbm.xml file and see if the behaviour changes.

I think that the collection only gets loaded if you explicitly request it or if the that lazy attribute is set to false. I think that applies to components as well as entities.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 7:23 am 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
You were right, thanks.

But now I have the next strange behaviour (or better: something is wrong in my implementation).

I am getting the list with the parts belonging to this vehicle. This list contains 2 elements (which is correct) but the size of list is 3?
And because of this I am getting a NullPointer because the first element is indeed null?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 8:02 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Macro,
it won't be possible.Plz check that have you added null in that list in code

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 9:46 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
hibernate expects the index-column to have continuous integers in it starting at 0. any missing numbers will have null objects placed in their spot in the List

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 9:59 am 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
kochcp wrote:
hibernate expects the index-column to have continuous integers in it starting at 0. any missing numbers will have null objects placed in their spot in the List

That's it. As expected, a beginner problem :-)
Thanks a lot


Top
 Profile  
 
 Post subject: Work Around
PostPosted: Wed Mar 14, 2007 12:42 pm 
Newbie

Joined: Wed Mar 14, 2007 11:36 am
Posts: 3
kochcp wrote:
hibernate expects the index-column to have continuous integers in it starting at 0. any missing numbers will have null objects placed in their spot in the List

Is there a work around to this? I'm having an issue where my join table has gaps between the ids (since the id columns are auto generated for both ends of the relationship) Here is an example where I am experiencing a problem.
I have an Order table, an OrderStatus table, an OrderStatusDetails table, and a Status table.
My Entities are defined like :
Code:
Order
   Integer Id;
   <List>OrderStatus orderStatus;
   
   @OneToMany(mappedBy="order")   
   @IndexColumn(name = "?????")
   getOrderStatus()
   
   
OrderStatus
   Order order;
   OrderStatusDetail orderStatusDetail;

   @ManyToOne
   @JoinColumn(name="OrderId")
   public Order getOrder() { return order; }

   @ManyToOne
   @JoinColumn(name="OrderStatusDetailsId")
   public OrderStatusDetail getOrderStatusDetail() { return orderStatusDetail; }



OrderStatusDetail
   Integer Id;
   Status status;
   Other fields for tracking

   @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
   public Integer getId() { return id; }
   
   @ManyToOne
   @JoinColumn(name="StatusCode", columnDefinition="character(5)")
   public Status getStatus() { return status; }
   
   
   
Status
   String Code;
   String Type;

   @Id
   @Column(name="Code", nullable=false, columnDefinition="character(5)")   
   public String getCode() { return code; }
   
   @Column(name="Type", nullable=false)
   public String getType() { return type; }



Here is the database with some sample data:
Code:
Order
Id          Other Columns
1            data,data,data
2            data,data,data
3            more data
...


OrderStatus (ordered by the OrderID)
OrderId     OrderStatusDetailsId
1               1
1               2              (we're good so far)
1               4              (now we're out of sequence - thus a null entry)
1               7
2               3
2               5
2               8
3               6
3               9
...

NOTE: Order 1 has a bunch of null entries because of the gaps


OrderStatusDetails
Id      StatusCode    Some Tracking Columns (who, when, where, etc)
1        '   01'      Tracking Data       (order 1 is opened)
2        '   02'      Tracking Data       (order 1 is approved)
3        '   01'      Tracking Data       (order 2 is opened)
4        '   03'      Tracking Data       (order 1 is filled)
5        '   02'      Tracking Data       (order 2 is approved)
6        '   01'      Tracking Data       (order 3 is opened)
7        '   04'      Tracking Data       (order 1 is shipped)
8        '   03'      Tracking Data       (order 2 is filled)
9        '   02'      Tracking Data       (order 3 is approved)
...

Status (Legacy Table with Code value as a Char(5))
Code         Type
'   01'      Opened
'   02'      Approved
'   03'      Filled
'   04'      Shipped
'   05'      Closed




The problem I'm getting is when I load my Order entity it's collection of OrderStatuses contains many null entries (this example has very few, but imagine once the OrderStatus and OrderStatusDetails tables fill up).

Any ideas on how I can change the mapping to eliminate the nulls?
I cannot change the DB schema so it all has to be managed within my entities and their relationships with each other.


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.