Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.8
Mapping documents:
Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.idiominc.gm.datamodel.TextString" table="TEXT_STRING">
<meta attribute="class-description">
Represents a text strings row in the database.
@author WAS
</meta>
<id name="sysKey" type="int" column="TEXT_STRING_SYSKEY">
<meta attribute="scope-set">public</meta>
<generator class="increment"/>
</id>
.
.
<map name="names" table="TEXT_STRING_STR">
<key column="TEXT_STRING_SYSKEY" foreign-key="false"/>
<index column="LANG_SYSKEY" type="int" />
<composite-element class="com.idiominc.gm.datamodel.TextStringDataPair">
<property name="body" column="TEXT_STRING_BODY" not-null="true" />
<property name="abbr" column="TEXT_STRING_ABBR" />
</composite-element>
</map>
<!--<many-to-one name="searchStrings"
class="com.idiominc.gm.datamodel.TextStringStrings"
column="TEXT_STRING_SYSKEY" insert="false" update="false" foreign-key="false" /> -->
.
.
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Quote:
Session hbSession = HibernateUtil.getSession();
Criteria searchCriteria = hbSession.createCriteria(TextString.class);
searchCriteria.add( Expression.eq("approvalStatus.sysKey", status));
searchCriteria.add(Expression.ilike("names.abbr", abbrev));
try
{
log.debug(loc + "doing search");
textStrings = searchCriteria.list(); // get the TextStrings
return textStrings;
}
catch (HibernateException e)
{
log.error(loc + ":"+ e.toString());
throw new GmDataAccessException(loc, e);
}
}
Full stack trace of any exception that occurs:Quote:
16:01:59,642 ERROR gm:131 - findTextStringObjects() :net.sf.hibernate.QueryException: could not resolve property: names.
abbr of: com.idiominc.gm.datamodel.TextString
<Jul 26, 2005 4:01:59 PM EDT> <Error> <HTTP> <BEA-101017> <[ServletContext(id=20704708,name=ws,context-path=/ws)] Root c
ause of ServletException.
java.lang.NullPointerException
at com.idiominc.gm.struts.action.objectstatus.SelectObjectsAction.executePerform(SelectObjectsAction.java:135)
at com.idiominc.gm.struts.action.GMBaseAction.execute(GMBaseAction.java:35)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6718)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
Name and version of the database you are using:Oracle 9.2.0.4.0
The generated SQL (show_sql=true):Quote:
16:44:07,722 INFO Environment:483 - Hibernate 2.1.8
16:44:07,722 INFO Environment:512 - hibernate.properties not found
16:44:07,722 INFO Environment:543 - using CGLIB reflection optimizer
16:44:07,722 INFO Environment:572 - using JDK 1.4 java.sql.Timestamp handling
16:44:07,738 INFO Configuration:909 - configuring from resource: /hibernate.cfg.xml
16:44:07,738 INFO Configuration:881 - Configuration resource: /hibernate.cfg.xml
16:44:10,113 INFO Configuration:332 - Mapping resource: com\idiominc\gm\datamodel\TextString.hbm.xml
16:44:10,144 INFO Binder:229 - Mapping class: com.idiominc.gm.datamodel.TextString -> TEXT_STRING
16:44:10,144 INFO Binder:571 - Mapping collection: com.idiominc.gm.datamodel.TextString.names -> TEXT_STRING_STR
16:44:11,597 INFO Configuration:675 - processing foreign key constraints
16:44:11,707 INFO Dialect:86 - Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
16:44:11,738 INFO SettingsFactory:74 - Use outer join fetching: true
16:44:11,769 INFO NamingHelper:26 - JNDI InitialContext properties:{}
16:44:11,769 INFO DatasourceConnectionProvider:51 - Using datasource: GmDevDB
16:44:11,769 INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
16:44:11,800 INFO TransactionManagerLookupFactory:38 - instantiating TransactionManagerLookup: net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
16:44:11,800 INFO TransactionManagerLookupFactory:42 - instantiated TransactionManagerLookup
16:44:12,128 INFO SettingsFactory:114 - Use scrollable result sets: true
16:44:12,144 INFO SettingsFactory:117 - Use JDBC3 getGeneratedKeys(): false
16:44:12,144 INFO SettingsFactory:120 - Optimize cache for minimal puts: false
16:44:12,144 INFO SettingsFactory:126 - echoing all SQL to stdout
16:44:12,144 INFO SettingsFactory:129 - Query language substitutions: {}
16:44:12,144 INFO SettingsFactory:140 - cache provider: net.sf.hibernate.cache.EhCacheProvider
16:44:12,160 INFO Configuration:1130 - instantiating and configuring caches
16:44:12,300 INFO SessionFactoryImpl:119 - building session factory
16:44:14,379 INFO SessionFactoryObjectFactory:86 - Factory name: HibernateFactory
16:44:14,379 INFO NamingHelper:26 - JNDI InitialContext properties:{}
16:44:14,410 INFO SessionFactoryObjectFactory:91 - Bound factory to JNDI name: HibernateFactory
16:44:14,410 WARN SessionFactoryObjectFactory:101 - InitialContext did not implement EventContext
16:44:14,410 INFO NamingHelper:26 - JNDI InitialContext properties:{}
16:44:14,535 DEBUG gm:45 - * gotSess Context: Sess=[net.sf.hibernate.impl.SessionImpl@196722d ]Thread [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] is open, tx=null, lang=null.
16:44:14,550 DEBUG gm:76 - * began Context: Sess=[net.sf.hibernate.impl.SessionImpl@196722d ]Thread [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] is open, tx=net.sf.hibernate.transaction.JDBCTransaction@17a82f1 isActive, lang=null.
16:44:15,410 DEBUG gm:79 - testCriteria: find TEXT_STRINGs.
16:44:15,425 DEBUG gm:106 - findTextStringObjects() parameters are:
16:44:15,441 DEBUG gm:107 - id: 1, status:3
16:44:15,441 DEBUG gm:108 - createdBy:JSINGER, modifiedBy:JSINGER
16:44:15,441 DEBUG gm:109 - TextStringQualifier: 4
16:44:15,441 DEBUG gm:110 - abbrev:fs%, text:first%
16:44:15,441 DEBUG gm:125 - findTextStringObjects() doing search
16:44:15,457 ERROR gm:131 - findTextStringObjects() :net.sf.hibernate.QueryException: could not resolve property: names.abbr of: com.idiominc.gm.datamodel.TextString
Query sql shown is mostly from a previous query in my application.
Debug level Hibernate log excerpt:It seems that hibernate does not allow me to access properties of the component object TextStringDataPair that is in the map called "names" in a Criterion: e.g.
Quote:
searchCriteria.add(Expression.ilike("names.abbr", abbrev));
.
The TEXT_STRING_STR table looks like this:
Quote:
CREATE TABLE TEXT_STRING_STR
(
TEXT_STRING_SYSKEY NUMBER NOT NULL,
LANG_SYSKEY NUMBER NOT NULL,
TEXT_STRING_BODY VARCHAR2(1000 BYTE) NOT NULL,
TEXT_STRING_ABBR VARCHAR2(200 BYTE)
)
We are currently doing internationalization by taking the map and getting the string we want by names.get(langId) kind of coding.
I have found that by creating a separate hibernate mapping, "TextStringStrings", that I can create a criterion; however, this breaks a lot of code that we already have that retrieves the map and does the get(langId).
Any ideas how I can use Criteria to access the composite-element properties that are in the "names" map? Thanks in advance.