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: How to avoid the creation of an empty collection?
PostPosted: Fri Mar 20, 2009 6:08 am 
Newbie

Joined: Wed Feb 25, 2009 3:17 am
Posts: 5
Location: Germany
Hello,

When an array is made persistent, hibernate generates an extra table for the array's content. E.g:

Code:
@Entity class A {
    @Id int id;
    B b;
}

@Embeddable class B {
    @CollectionOfElements @IndexColumn(name="arrayIndex") C[] c;
}

@Embeddable class C {
    String bla;
}


I create an instance of A where A.b is null and persistify this instance. The extra table has no content and the b column of the A table is null - fine

However, when I try to retrieve the A member instance, hibernate creates the A.b instance with an empty collection. How can this be avoided?

The hibernate debug log contains:

Code:
2009-03-20 10:50:27 DEBUG: loading collection: [A.B.c#testId]
2009-03-20 10:50:27 DEBUG: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-03-20 10:50:27 DEBUG:
    select ...
2009-03-20 10:50:27 DEBUG: about to open ResultSet (open ResultSets: 0, globally: 0)
2009-03-20 10:50:27 DEBUG: result set contains (possibly empty) collection: [A.B.c#testId]
2009-03-20 10:50:27 DEBUG: about to close ResultSet (open ResultSets: 1, globally: 1)
2009-03-20 10:50:27 DEBUG: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-03-20 10:50:27 DEBUG: 1 collections were found in result set for role: A.B.c
2009-03-20 10:50:27 DEBUG: collection fully initialized: [A.B.c#testId]
2009-03-20 10:50:27 DEBUG: 1 collections initialized for role: A.B.c
2009-03-20 10:50:27 DEBUG: done loading collection


Thank you,
Robert


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.