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
|