-->
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: MySQL drivers 3.1.x and Null objects when querying
PostPosted: Mon Aug 08, 2005 2:27 pm 
Beginner
Beginner

Joined: Mon Mar 28, 2005 12:58 pm
Posts: 27
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1 beta1 and anootations Beta4

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I am running MySQL 4.1.11 with a JDBC driver 3.1.10 and I was getting strange NullPointerExceptions when creating an Organization and reading it back out. Let's start with the entity definitions.

The Organization (and its parent Party) classes are defined like this:
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name = "Org")
public class Organization extends Party
{
    @Transient
    public Long getOrgId()
    {
        return getPartyId();
    }

    public void setOrgId(final Long orgId)
    {
        setPartyId(orgId);
    }
}

@Entity()
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name = "Party")
public class Party
{
    private Long partyId;

    @Id(generate=GeneratorType.AUTO)
    @Column(name = PK_COLUMN_NAME)       
    public Long getPartyId()
    {
        return partyId;
    }

    protected void setPartyId(final Long partyId)
    {
        this.partyId = partyId;
    }
}

So it's a pretty straight forward relationship and the test code is like this:

Code:
        Session session = openSession();
        Transaction transaction = session.beginTransaction();

        final Organization blueCross = new Organization();
        blueCross.setOrganizationName("Blue Cross Blue Shield");       
        session.save(blueCross);
        transaction.commit();
        session.close();

        session = openSession();
        final Organization blueCross2 = (Organization) session.createCriteria(Organization.class).add(Restrictions.eq("partyId", blueCross.getOrgId())).uniqueResult();
        assertThat(blueCross2.getOrganizationName(), eq(blueCross.getOrganizationName()));


So the NPE is being thrown at the assertThat line on the blueCross2.getOrganizationName(). Something simple like this and it was not retrieving the object back. If I don't use the .add(Restrictions.eq("partyId", blueCross.getOrgId())) part in the criteria then a valid Organization comes back and the test passes (there are no other orgs in the database). This really had me baffled until I saw this post: http://forum.hibernate.org/viewtopic.php?t=945424

So I rolled back to mysql driver version 3.0.17 and IT WORKED but this makes no sense at all. Has anyone seen this behavior at all? It would be nice to find out what the actual cause was because it's killing me. :)


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.