-->
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: NullPointerException: join fetch & set of composite-elements
PostPosted: Mon Jul 27, 2009 4:32 pm 
Newbie

Joined: Mon Jul 27, 2009 4:15 pm
Posts: 1
Class Company has a many-to-one relationship to Person (chief) which has a set of composite-elements (addresses). The Line:
Session.createQuery(
"from Company c
join fetch c.owner o
join fetch o.addresses a")

produces a Nullpointer Exception.

Here is my test code (tested with hibernate-core-3.3.0.SP1):


Configuration cfg =
new Configuration().addDirectory(new File("src/main/java/org/donmiguel"));

Properties p = new Properties();
p.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
p.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
p.setProperty("hibernate.hbm2ddl.auto", "create-drop");
p.setProperty("hibernate.connection.username", "sa");
p.setProperty("hibernate.connection.password", "");
p.setProperty("hibernate.connection.url", "jdbc:hsqldb:file:testdb");
p.setProperty("hibernate.show_sql", "true");
p.setProperty("hibernate.format_sql", "true");
cfg.setProperties(p);
SessionFactory sessionFactory = cfg.buildSessionFactory();

Session session = sessionFactory.openSession();
Query query = session.createQuery(//
"from Company c " //
+ "join fetch c.owner o " //
+ "join fetch o.addresses a"//
);


Here is the occuring Exception:

java.lang.NullPointerException
at org.hibernate.loader.BasicLoader.isBag(BasicLoader.java:94)
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:76)
at org.hibernate.loader.hql.QueryLoader.<init>(QueryLoader.java:119)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:204)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
at org.donmiguel.TestHibernate.test(TestHibernate.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

And here are my classes:

public class Company {
private Long id;
private Person owner;

public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
}

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.donmiguel">
<class name="Company">
<id name="id">
<generator class="native" />
</id>
<many-to-one name="owner"/>
</class>
</hibernate-mapping>

public class Person {
private Long id;
private Set<Address> addresses;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<Address> getAddresses() {
return addresses;
}
public void setAddresses(Set<Address> addresses) {
this.addresses = addresses;
}
}

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.donmiguel">
<class name="Person">
<id name="id">
<generator class="native" />
</id>
<set name="addresses">
<key column="person_id" />
<composite-element class="Address">
<property name="country" />
<property name="street" />
</composite-element>
</set>
</class>
</hibernate-mapping>


public class Address {
private String street;
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}


Please, could anyone tell me, if I'm doing something wrong? Is the mapping incorrect? Any comments are welcome.


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.