-->
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.  [ 5 posts ] 
Author Message
 Post subject: NullPointerException on adding Order.asc to child class
PostPosted: Thu Dec 09, 2004 2:13 pm 
Newbie

Joined: Thu Apr 29, 2004 11:40 am
Posts: 11
Hibernate works perfectly until I try and execute:
searchCriteria.addOrder( Order.asc( "pc.intranetId" ) );
which cause a NullPointerException...

Any thoughts? I've got no clue on this one.
Thanks in advance

Many details below!

Hibernate version:
2.1.7c

Mapping documents:

<hibernate-mapping>
<class
name="com.pg.webcc.contract.Contract"
table="CONTRACT"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="CONTRACT_ID"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>

<!-- Skipping extraneous fields -->

<many-to-one
name="primaryContact"
class="com.pg.DescriptivePGEmployee"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="primaryContact"
/>

<!-- Skipping extraneous fields -->
</class>

</hibernate-mapping>

<hibernate-mapping>
<class
name="com.pg.PGEmployee"
table="PGEMPLOYEE"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="PGEMPLOYEE_ID"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>

<property
name="intranetId"
type="java.lang.String"
update="true"
insert="true"
column="intranetId"
/>

<joined-subclass
name="com.pg.DescriptivePGEmployee"
table="DESCRIPTIVE_PGEMPLOYEE"
dynamic-update="false"
dynamic-insert="false"
>
<key
column="PGEMPLOYEE_ID"
/>


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

try {
Session session = HibernateSessionFactory.currentSession();
Criteria searchCriteria = session.createCriteria(Contract.class);
searchCriteria.createAlias("contractSpecialist", "cs");
searchCriteria.createAlias("primaryContact", "pc");

// Search Specifications
if ( searchType == QuickSearchTypeEnumeration.CONTRACT_SPECIALIST ) {
searchCriteria.add( Expression.ilike("cs.intranetId", query ) );
}
if ( searchType == QuickSearchTypeEnumeration.CONTRACT_NUMER ) {
searchCriteria.add( Expression.like( "contractNumber", query ) );
}
if ( searchType == QuickSearchTypeEnumeration.ORGANIZATION ) {
searchCriteria.add( Expression.like( "pc.deptDivision", query ) );
}
//TODO Enhancement : Currently only works with intranetId
if ( searchType == QuickSearchTypeEnumeration.PRIMARY_CONTACT ) {
searchCriteria.add( Expression.like( "pc.intranetId", query ) );
}

// Search Ordering
if ( searchOrder == SearchOrderEnumeration.PRIMARY_CONTACT ) {
searchCriteria.addOrder( Order.asc( "pc.intranetId" ) );
}
if ( searchOrder == SearchOrderEnumeration.CONTRACT_SPECIALIST ) {
searchCriteria.addOrder( Order.asc("cs.intranetId" ) );
}

List results = searchCriteria.list();

request.setAttribute(RESULTS_KEY, results);
request.setAttribute(ACTION_KEY, ACTION);
return mapping.findForward(TO_RESULTS);

} catch ( HibernateException ex ) {
// TODO: Exception Handling
} finally {
try {
HibernateSessionFactory.closeSession();
} catch (HibernateException e) {}
}

Full stack trace of any exception that occurs:
java.lang.NullPointerException
at net.sf.hibernate.persister.NormalizedEntityPersister.toColumns(NormalizedEntityPersister.java:1067)
at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:42)
at net.sf.hibernate.expression.Order.toSqlString(Order.java:37)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:78)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3630)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.pg.webcc.struts.action.QuickSearchAction.execute(QuickSearchAction.java:89)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:252)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

Name and version of the database you are using:
Microsoft SQL Server 2000

The generated SQL (show_sql=true):
Error generated before sql creation

Debug level Hibernate log excerpt:

- Hibernate 2.1.7
- hibernate.properties not found
- using CGLIB reflection optimizer
- using JDK 1.4 java.sql.Timestamp handling
- configuring from resource: /hibernate.cfg.xml
- Configuration resource: /hibernate.cfg.xml
- Mapping resource: com/pg/webcc/contract/Contract.hbm.xml
- Mapping class: com.pg.webcc.contract.Contract -> CONTRACT
- Mapping joined-subclass: com.pg.webcc.contract.ConfidentialDisclosureAgreement -> CONFIDENTIAL_DISCLOSURE
- Mapping joined-subclass: com.pg.webcc.contract.ConsultingAgreement -> CONSULTING_AGREEMENT
- Mapping joined-subclass: com.pg.webcc.contract.NonStandardContract -> NON_STANDARD_CONTRACT
- Mapping joined-subclass: com.pg.webcc.contract.ResearchAgreement -> RESEARCH_AGREEMENT
- Mapping joined-subclass: com.pg.webcc.contract.ClinicalStudyAgreement -> CLINICAL_STUDY
- Mapping joined-subclass: com.pg.webcc.contract.ContractGiftLetter -> CONTRACT_GIFT_LETTER
- Mapping joined-subclass: com.pg.webcc.contract.ServiceAgreement -> SERVICE_AGREEMENT
- Mapping joined-subclass: com.pg.webcc.contract.MaterialsTransferAgreement -> MATERIAL_TRANSFER
- Mapping joined-subclass: com.pg.webcc.contract.ContractExtension -> CONTRACT_EXTENTION
- Mapping resource: com/pg/Address.hbm.xml
- Mapping class: com.pg.Address -> ADDRESS
- Mapping resource: com/pg/ReferenceData.hbm.xml
- Mapping class: com.pg.ReferenceData -> REFERENCE_DATA
- Mapping resource: com/pg/PGEmployee.hbm.xml
- Mapping class: com.pg.PGEmployee -> PGEMPLOYEE
- Mapping joined-subclass: com.pg.DescriptivePGEmployee -> DESCRIPTIVE_PGEMPLOYEE
- Mapping joined-subclass: com.pg.TitledPGEmployee -> TITLED_PGEMPLOYEE
- Mapping resource: com/pg/webcc/external/ContractParty.hbm.xml
- Mapping class: com.pg.webcc.external.ContractParty -> CONTRACT_PARTY
- Mapping joined-subclass: com.pg.webcc.external.IndividualParty -> INDIVIDUAL_PARTY
- Mapping joined-subclass: com.pg.webcc.external.CompanyParty -> COMPANY_PARTY
- Mapping resource: com/pg/Currency.hbm.xml
- Mapping class: com.pg.Currency -> CURRENCY
- Configured SessionFactory: null
- processing one-to-many association mappings
- processing one-to-one association property references
- processing foreign key constraints
- Using dialect: net.sf.hibernate.dialect.SQLServerDialect
- Use outer join fetching: true
- Using Hibernate built-in connection pool (not for production use!)
- Hibernate connection pool size: 20
- using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver://whbc-inet03:1433;DatabaseName=webcc;SelectMethod=Cursor
- connection properties: {user=webcc_user, password=tradingwebspaces}
- No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
- Use scrollable result sets: true
- Use JDBC3 getGeneratedKeys(): false
- Optimize cache for minimal puts: false
- echoing all SQL to stdout
- Query language substitutions: {}
- cache provider: net.sf.hibernate.cache.EhCacheProvider
- instantiating and configuring caches
- building session factory
- Not binding factory to JNDI, no JNDI name configured


Top
 Profile  
 
 Post subject: Same deal for other Actions...
PostPosted: Thu Dec 09, 2004 8:00 pm 
Newbie

Joined: Thu Apr 29, 2004 11:40 am
Posts: 11
Throughs the same error from a different action with an even simpler criteria:

Criteria c = session.createCriteria(Contract.class);
c.createAlias ( "primaryContact", "pc");
session.addOrder(Order.asc("pc.intranetId"));

I guess I should move it to a unit test to play around with now...


Top
 Profile  
 
 Post subject: JUnit Test
PostPosted: Thu Dec 09, 2004 10:15 pm 
Newbie

Joined: Thu Apr 29, 2004 11:40 am
Posts: 11
This JUnit test fails with the same exception.

public void testSorting() throws HibernateException {
Session session = HibernateSessionFactory.currentSession();
Criteria criteria = session.createCriteria( Contract.class );
criteria.createAlias("primaryContact", "pc");
criteria.addOrder( Order.asc("pc.intranetId") );
List results = criteria.list();

Iterator i = results.iterator();
while ( i.hasNext() ) {
Contract c = (Contract)i.next();
System.out.println( "Intranet Id >> " + c.getPrimaryContact().getIntranetId() );
}
}


Top
 Profile  
 
 Post subject: Works when using Query? (HQL)
PostPosted: Thu Dec 09, 2004 10:51 pm 
Newbie

Joined: Thu Apr 29, 2004 11:40 am
Posts: 11
The exact same logical operations work pefectly fine when using HQL. Odd?

public void testSortingQuery() throws HibernateException {
Session session = HibernateSessionFactory.currentSession();
Query query = session.createQuery("from Contract as c order by c.primaryContact.intranetId");
List results = query.list();

Iterator i = results.iterator();
while ( i.hasNext() ) {
Contract c = (Contract)i.next();
System.out.println( "Intranet Id >> " + c.getPrimaryContact().getIntranetId() );
}
HibernateSessionFactory.closeSession();
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This was due to the fact that HB 2.1 does not support ordering by a joined criteria. This is possible in HB3.


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