-->
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.  [ 2 posts ] 
Author Message
 Post subject: Null values as part of an unique key
PostPosted: Wed May 31, 2006 10:11 am 
Newbie

Joined: Wed May 31, 2006 8:42 am
Posts: 1
Location: Belgium
I'm using the Hibernate Tool 3.1 to map an old database(oracle 9.2).
The database didn't had any primary keys defined, so I use hibernate.reveng.xml to define the colums that make an unique key(with composite-id).
With hibernate tools I create my 'Domain Code' and '.hbm.xml' files.

Now when I try to get an object with get and I give a long and a Short variable, I get my Object back without any problems.
But when I want to get the object where one of the variable has the value 'null' in my database, I get a 'java.lang.NullPointerException'.
When I look in my database there is only one row that corresponds with it.
I have asked around I have heard that hibernate has problems with null values. Is there any way around, so the null values aren't a problem?

Example:

Part of TestClass working code:
Code:
    Kssv k = kssvDao.getKssv(new KssvId(11, new Short("1")));


Part of TestClass failling code:
Code:
    Kssv k = kssvDao.getKssv(new KssvId(11, null));


Constructor of KssvId
Code:
    public KssvId(long kssvnr, Short kssvagentnr) {
        this.kssvnr = kssvnr;
        this.kssvagentnr = kssvagentnr;
    }


Part of KssvDaoImpl:
Code:
    public Kssv getKssv(KssvId inId) {
        Validate.notNull(inId, "inId cannot be null");
        try {
            return (Kssv) this.getHibernateTemplate().get(Kssv.class, inId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
a primary key/identifier cannot contain null.

_________________
Max
Don't forget to rate


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