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.