-->
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: Hibernate throwing NPE due to composite OneToMany mapping
PostPosted: Tue May 06, 2014 3:27 pm 
Newbie

Joined: Mon Apr 07, 2014 10:20 am
Posts: 12
I am working against a legacy database with two tables that look something like this...

Code:
Two tables:

Detail                   Criteria
---------------------------------
*name                    *cri_id
*grp_id                  *grp_id
cri_id                   *seqnum

* Fields marked with an asterisk are PKs


Note that this technically could be a ManyToMany mapping (a given detail obviously links to multiple criteria since we're not joining against the seqnum column. However, the same criteria can also be pointed to by multiple detail records. But, since there's no middle join table so this isn't really a correct ManyToMany mapping (I have to work with what I'm given).

Anyway, I have tried to map this in Hibernate like so...

Code:
public class Detail {
...
    @OneToMany
    @JoinColumns({
            @JoinColumn(name = "cri_id", referencedColumnName = "cri_id", insertable = false, updatable = false),
            @JoinColumn(name = "grp_id", referencedColumnName = "grp_id", insertable = false, updatable = false)
            // Note that we're NOT joining on the seqnum column also, here ---
    })
    @OrderBy("sequenceNumber ASC")
    private List<Criteria> criteria = Lists.newArrayList();

    @Column(name = "cri_id")
    private String criteriaId;
    ...
}


This gives a null pointer exception during initialization in the Hibernate code...

Code:
java.lang.NullPointerException
   at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1456)
   at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:864)
   at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:779)
   at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
   at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
   at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    ...


If I remove the above mapping (or simply mark it as @Transient) Hibernate initializes fine. I realize this is kind of a borked table structure so is there a better method to performing this mapping or is this a Hibernate limitation due to the odd mapping?


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.