Hi,
Firstly appolgoise for the long post!
I am having trouble searching and writing a object to the database. I have mapped the object via the hbm.xml but when hibernate performs its query it sayes the object is not mapped.
to explain further:
I have a parent class cp which has 2 subclasses cplive and cptemp
In the parebt object i have all the setters and getters and in the cplive i have couple of extra fields as in the temp. all mapped.
My hbm.xml for the live is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!-- change reference to DTD -->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- <!DOCTYPE hibernate-mapping SYSTEM
"file:///C:/apps/hibernate-3.1/src/org/hibernate/hibernate-mapping-3.0.dtd"> -->
<hibernate-mapping>
<class name="com.my.valueobjs.CPPersistent" table="CP">
<id type="java.lang.String">
</id>
<property name="cpId" column="CPID"/>
<property name="clientName" column="CLIENTNAME" not-null="true"/>
<property name="london" column="LONDON" not-null="true"/>
<property name="newyork" column="NEWYORK" not-null="true"/>
</class>
</hibernate-mapping>
The Id field in the mapping is generated by the user when he fills in the form from the web fornt end. Before i tried the above i had
<id name="cpId" column="CPID"
</id>
In my code I do the following query when performing a search:
public List findById(String Id, String table) {
log.debug("entered find by Id: " + Id);
HibernateTemplate hibTemp = getHibernateTemplate();
List results = new ArrayList();
if(table.equalsIgnoreCase("live"))
{
results = hibTemp.find("from CPPersistent as cp where cp.cpId = '" + Id + "'");
}
When I try to execute the following code I get the following exception:
11:56:00,838 DEBUG TransactionSynchronizationManager:136 - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@f 800db] for key [org.hibernate.impl.SessionFactoryImpl@b95f72] bound to thread [http-8080-Processor3]
11:56:00,849 DEBUG HibernateTemplate:350 - Found thread-bound Session for HibernateTemplate
11:56:00,869 DEBUG TransactionSynchronizationManager:136 - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@f 800db] for key [org.hibernate.impl.SessionFactoryImpl@b95f72] bound to thread [http-8080-Processor3]
11:56:00,879 DEBUG SessionImpl:1005 - find: from CPPersistent as cp where cp.cpId = 'dsfrwef'
11:56:00,899 DEBUG QueryParameters:261 - named parameters: {}
11:56:01,049 DEBUG QueryTranslatorImpl:234 - parse() - HQL: from CPPersistent as cp where cp.cpId = 'dsfrwef'
11:56:01,079 DEBUG AST:250 - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'from'
| \-[RANGE] 'RANGE'
| +-[IDENT] 'CPPersistent'
| \-[ALIAS] 'cp'
\-[WHERE] 'where'
\-[EQ] '='
+-[DOT] '.'
| +-[IDENT] 'cp'
| \-[IDENT] 'cpd'
\-[QUOTED_STRING] ''dsfrwef''
11:56:01,089 DEBUG ErrorCounter:68 - throwQueryException() : no errors
11:56:01,089 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
org.springframework.orm.hibernate3.HibernateQueryE xception: CPPersistent is not mapped. [from CPPersistent as cp where cp.cpId = 'dsfrwef']; nested exception is org.hibernate.hql.ast.QuerySyntaxException: CPPersistent is not mapped. [from CPPersistent as cp where cp.cpId = 'dsfrwef']
I cant undersatnd why I get this object not mapped exception as earlier in my log it prints out the following
11:53:55,628 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hib...apping-3.0.dtd in classpath under org/hibernate/
11:53:55,638 DEBUG DTDEntityResolver:56 - found http://hibernate.sourceforge.net/hib...apping-3.0.dtd in classpath
11:53:55,859 INFO HbmBinder:266 - Mapping class: com.my.CPPersistent -> CP
11:53:55,949 DEBUG HbmBinder:1179 - Mapped property: cpId -> CPID
11:53:55,949 DEBUG HbmBinder:1179 - Mapped property: clientName -> CLIENTNAME
11:53:55,949 DEBUG HbmBinder:1179 - Mapped property: london -> LONDON
11:53:55,949 DEBUG HbmBinder:1179 - Mapped property: newyork -> NEWYORK
11:53:55,949 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hib...apping-3.0.dtd in classpath under org/hibernate/
All help is greatly appreciated as I have tried a few things namely messing with the ID in the mapping and none have worked. I think it may be something to do with this but am not sure.
thanks


Reply With Quote
rogramCode_in" + " ) " +


