-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with the sql generated using hibernate unknown colum
PostPosted: Wed Aug 31, 2005 2:43 am 
Newbie

Joined: Thu Aug 18, 2005 1:46 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b]
Hibernate 3.0.
[b]Mapping documents:[/b]

1.HistoryEntry
----------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.srit.pacs.hibernate.HistoryEntry" table="HISTORY_ENTRIES">
<id name="id" type="int">
<column name="pk"/>
<generator class="increment"/>
</id>
<property name="who" column="who" type="string"/>
<property name="what" column="what" type="string"/>
<property name="hostname" column="hostname" type="string"/>
<property name="username" column="username" type="string"/>
<property name="objectName" column="object_name" type="string"/>
<property name="property" column="property" type="string"/>
<property name="eventDateTime" column="event_dateTime" type="timestamp"/>
<property name="oldValue" column="oldvalue" type="string"/>
<property name="newValue" column="newvalue" type="string"/>
</class>
</hibernate-mapping>

2.CountryMaster
-------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.srit.pacs.hibernate.CountryMaster" table="country_master">
<id name="id" type="int">
<column name="pk"/>
<generator class="increment"/>
</id>
<property name="countryName" column="country_name" type="string" not-null="true" />
<property name="description" column="description" type="string" />
<set name="historyEntries" table="HISTORY_ENTRIES" inverse="true">
<key column="pk"/><many-to-many class="com.srit.pacs.hibernate.HistoryEntry"/>
</set>
</class>
</hibernate-mapping>

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]
Aug 31, 2005 11:31:26 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1054, SQLState: S0022
Aug 31, 2005 11:31:26 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column not found, message from server: "Unknown column 'historyent0_.elt' in 'field list'"
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.salmonllc.sql.DSDataRow.populateFromBean(DSDataRow.java:839)
at com.salmonllc.sql.DSDataRow.populateFromBean(DSDataRow.java:819)
at com.salmonllc.sql.BeanDataStore.insertRow(BeanDataStore.java:399)
at com.salmonllc.sql.BeanDataStore.insertRow(BeanDataStore.java:377)
at com.salmonllc.sql.BeanDataStore.insertRow(BeanDataStore.java:361)
at com.salmonllc.sql.BeanDataStore.insertRows(BeanDataStore.java:411)
at com.salmonllc.sql.BeanDataStore.insertRows(BeanDataStore.java:420)
at com.salmonllc.hibernate.HibernateDataStore.execute(HibernateDataStore.java:168)
at com.salmonllc.hibernate.HibernateDataStore.retrieve(HibernateDataStore.java:128)
at com.salmonllc.hibernate.HibernateDataStore.retrieve(HibernateDataStore.java:175)
at com.salmonllc.hibernate.HibernateDataStore.autoRetrieve(HibernateDataStore.java:295)
at com.salmonllc.jsp.JspController.doAutoRetrieve(JspController.java:1711)
at com.salmonllc.jsp.JspController.doGet(JspController.java:684)
at com.salmonllc.jsp.tags.PageTag.doStartTag(PageTag.java:224)
at org.apache.jsp.Jsp.CountryMaster_jsp._jspx_meth_jade_page_0(org.apache.jsp.Jsp.CountryMaster_jsp:96)
at org.apache.jsp.Jsp.CountryMaster_jsp._jspService(org.apache.jsp.Jsp.CountryMaster_jsp:53)
at com.salmonllc.jsp.JspServlet.service(JspServlet.java:332)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)
Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.srit.pacs.hibernate.CountryMaster.historyEntries#195]
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1367)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:105)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1353)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:170)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
at org.hibernate.collection.PersistentSet.isEmpty(PersistentSet.java:117)
... 51 more
Caused by: java.sql.SQLException: Column not found, message from server: "Unknown column 'historyent0_.elt' in 'field list'"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1905)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2090)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1496)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1197)
at org.hibernate.loader.Loader.doQuery(Loader.java:366)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1360)
... 58 more
[b]Name and version of the database you are using:[/b]

[b]The generated SQL (show_sql=true):[/b]
Hibernate: select historyent0_.pk as pk__, historyent0_.elt as elt__, historyent1_.pk as pk0_, historyent1_.who as who1_0_, historyent1_.what as what1_0_, historyent1_.hostname as hostname1_0_, historyent1_.username as username1_0_, historyent1_.object_name as object6_1_0_, historyent1_.property as property1_0_, historyent1_.event_dateTime as event8_1_0_, historyent1_.oldvalue as oldvalue1_0_, historyent1_.newvalue as newvalue1_0_ from HISTORY_ENTRIES historyent0_ inner join HISTORY_ENTRIES historyent1_ on historyent0_.elt=historyent1_.pk where historyent0_.pk=?

[b]Debug level Hibernate log excerpt:[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 5:59 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
Looks like you have to change the relationship type in CountryMaster mapping from many-to-many to one-to-many, since I suppose you want to keep multiple history entries for particular CountryMaster. To accomplish this you will also need to add new column to history entry to store the pk from CountryMaster alongs with HistoryEntries pk.

But if you need to have many-to-many relationship between CountryMaster and HistortEntries, then you need to create so-called link table like CountryMaster_HistoryLink table with only to columns, pk1 from CountryMaster, pk2 from HistoryEntries. In CountryMaster mapping you will need to change the table name from HistoryEntires to CountryMaster_HistoryLink table.

how this will help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 2:42 pm 
Newbie

Joined: Thu Aug 18, 2005 1:46 am
Posts: 4
thank you very much ....i did the second option that you specified and got the problem resolved!!


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