-->
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.  [ 4 posts ] 
Author Message
 Post subject: Custom Mapping Class using Same Table
PostPosted: Tue Sep 21, 2004 7:22 am 
Newbie

Joined: Tue Sep 21, 2004 6:57 am
Posts: 3
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]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 21, 2004 7:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Sounds to me pretty much like a component or dynamic component


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 21, 2004 7:34 am 
Newbie

Joined: Tue Sep 21, 2004 6:57 am
Posts: 3
michael wrote:
Sounds to me pretty much like a component or dynamic component


OK, thanks - I'll investigate that some more. I did look at the reference for components; I thought that they were unecessarily complex for just reading from the DB. I'm think I'm on the wrong track with my solution, though, so I will examine components more in depth.

Cheers,
Jenny


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 4:34 am 
Newbie

Joined: Tue Sep 21, 2004 6:57 am
Posts: 3
You were absolutely right. Once I'd looked at some examples, it made more sense. It's working now, thanks.


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