Hello, there,
My table NEWS has columns CONTENT1, CONTENT2,... CONTENT5. I want to consolidate those columns into one object called Content which is just a list of any of the CONTENTx columns that are not null. So instead of my News object having properties content1.. content5, it would have a property Content content with a getter and setter.
I wrote a custom mapping class to get the content from the DB and it works fine. When I try to integrate Content into News, however, the program squawks. Originally it threw an Illegal Argument Exception saying that I was trying call setContent(Content content) with a paramater of type News. I can't recreate that error, however, since I restarted my server. Now I get an exception that says
Could not execute query: "NEWS.CONTENT" is not valid in the context where it is used.
I recognize that the find is adding a default search value for the News property content, which is not mentioned in my News mapping. I know that I can write a more specific find query, but I can't think how the content would then be set on News if I do it that way. I'd appreciate some help or criticisms with how I've approached this.
Thanks in advance,
Jenny
Hibernate version: 2.1.6
Mapping documents:
Code:
<hibernate-mapping>
<class name="co.uk.news.hibernate.model.NewsImpl" table="NEWS">
<id name="id" >
<column name="ID"/>
<generator class="assigned"/>
</id>
<property name="headLine" column="HEADLINE"/>
<property name="newsType" column="NEWSTYPE"/>
<one-to-one name="content" class="co.uk.news.hibernate.model.Content"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="co.uk.news.hibernate.model.Content" table="NEWS">
<id name="id">
<column name="ID"/>
<generator class="assigned"/>
</id>
<property name="content1" column="CONTENT1"/>
<property name="content2" column="CONTENT2"/>
<property name="content3" column="CONTENT3"/>
<property name="content4" column="CONTENT4"/>
<property name="content5" column="CONTENT5"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
List list = session.find("from news in class co.uk.news.hibernate.model.NewsImpl");
System.err.println(list.size());
Full stack trace of any exception that occurs:Code:
[21/09/04 12:05:33:631 BST] 27d127d1 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter Could not execute query
[21/09/04 12:05:33:972 BST] 27d127d1 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter TRAS0014I: The following exception was logged COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0206N "NEWS.CONTENT" is not valid in the context where it is used. SQLSTATE=42703
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at java.sql.SQLException.<init>(SQLException.java:51)
at COM.ibm.db2.jdbc.DB2Exception.<init>(DB2Exception.java:72)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:270)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:207)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(SQLExceptionGenerator.java:458)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(DB2PreparedStatement.java:2110)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeQuery(DB2PreparedStatement.java:1596)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
Name and version of the database you are using:IBM DB2 v7 FP2
The generated SQL (show_sql=true):Code:
select news.ID as ID, news.HEADLINE as HEADLINE, news.NEWSTYPE as NEWSTYPE, news.content as content from NEWS news
Debug level Hibernate log excerpt:none
[/code]