For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 4 replies, 2 voices, and was last updated 19 years, 2 months ago by
Haris Peco.
-
AuthorPosts
-
jastarafieMemberHello everybody,
I am developing a cost allocation system for a brewery.
I’ve got two tables: Brewery and Project, mappings in hibernate:<?xml version="1.0" encoding="UTF-8"?> //brewery <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="business"> <class name="Brewery" table="brewery" > <id name="brewery_id" type="string" column="brewery_id"></id> <property name="street" type="string"></property> <property name="house_nr" type="integer"></property> <property name="city" type="string"></property> <property name="zip_code" type="integer"></property> <property name="country" type="string"></property> <property name="tel_nr" type="string"></property> <set name="brewery_id" table="project"> <key column="brewery_id" /> <one-to-many class="business.Project" /> </set> </class> </hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>//project <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="business"> <class name="Project" table="project" > <id name="project_id" type="string" column="project_id"> </id> <property name="start_date" type="date"></property> <property name="end_date" type="date"></property> <many-to-one name="brewery_id" class="business.Brewery" column="brewery_id" /> </class> </hibernate-mapping>
I have two comboboxes, the first one is with the project names, and the second is with the brewery names BUT depending on the value of the first combobox.
So i wrote an postgresql command to get the associated breweries:public Vector getBreweryNames(String id){ Vector result = new Vector(); try{ String sqlQuery = "select pro.brewery_id from Project as pro where pro.project_id = " + id; Query myQuery = DBmanager.getInstance().getSession().createQuery(sqlQuery); Iterator help = myQuery.iterate(); //put the values of the iterator in the Vector! while(help.hasNext()) result.add(help.next()); } catch(Exception e){ e.printStackTrace(); } return result; }
resulting in this error, where i cant make anything out, except that column cosas doesn’t exist, but it does!!!
So I need a little bit of help… thanx in advance…Hibernate: select project0_.brewery_id as col_0_0_ from project project0_ where project0_.project_id=cosas org.hibernate.exception.SQLGrammarException: could not execute query using iterate at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:420) at org.hibernate.hql.ast.QueryTranslatorImpl.iterate(QueryTranslatorImpl.java:318) at org.hibernate.engine.query.HQLQueryPlan.performIterate(HQLQueryPlan.java:177) at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1156) at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:46) at data.ProjectGetter.getBreweryNames(ProjectGetter.java:47) at application.ProjectController.getAllBreweryNames(ProjectController.java:35) at gui.content.RegistrationJPanel$2.actionPerformed(RegistrationJPanel.java:128) at javax.swing.JComboBox.fireActionEvent(Unknown Source) at javax.swing.JComboBox.setSelectedItem(Unknown Source) at javax.swing.JComboBox.setSelectedIndex(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) Caused by: org.postgresql.util.PSQLException: ERROR: column "rukken" does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1527) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1311) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:190) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:258) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139) at org.hibernate.loader.Loader.getResultSet(Loader.java:1669) at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:397) ... 32 more 15:39:28,578 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 42703 15:39:28,578 ERROR JDBCExceptionReporter:72 - ERROR: column "cosas" does not exist
June 6, 2006 at 12:00 pm #253149
Haris PecoMemberjastarafie ,
from your mapping i suppose that you want next query :
…
String sqlQuery = “select pro.brewery_id from Project as pro where pro.project_id = ?”;
Query myQuery = DBmanager.getInstance().getSession().createQuery(sqlQuery);
myQuery.setParameter(0,id);
…in your Vector you will have objects type Brewery (no brewery_id).
you got messages that column cosas doesn’t exists (and it is true), but no value ‘cosas’ for column project_id
other way (worse) :
String sqlQuery = “select pro.brewery_id from Project as pro where pro.project_id = ‘” + id + “‘”;
Query myQuery = DBmanager.getInstance().getSession().createQuery(sqlQuery);your String ‘id’ have single quotes
Best regards
June 6, 2006 at 12:46 pm #253158
jastarafieMemberThank you sooooo much, the (worse) solution helped…
June 7, 2006 at 6:18 am #253202
jastarafieMemberAdditional question:
When I add the same project to two different breweries, e.g. cosas, then the following error comes up when the query from above is executed.
Exception in thread "AWT-EventQueue-0" org.hibernate.HibernateException: More than one row with the given identifier was found: cosas , for class: business.Project at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:68) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:820) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158) at business.Project$$EnhancerByCGLIB$$abbb019d.toString(<generated>) at javax.swing.DefaultListCellRenderer.getListCellRendererComponent(Unknown Source) at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source) at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source) at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source) at javax.swing.JComponent.getPreferredSize(Unknown Source) at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source) at java.awt.Container.layout(Unknown Source) at java.awt.Container.doLayout(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validate(Unknown Source) at javax.swing.JLayeredPane.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at gui.MainGUI.setActiveJPanel(MainGUI.java:216) at gui.MainGUI.access$2(MainGUI.java:212) at gui.MainGUI$7.actionPerformed(MainGUI.java:182) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) 13:09:47,265 INFO DefaultLoadEventListener:95 - Error performing load command org.hibernate.HibernateException: More than one row with the given identifier was found: cosas , for class: business.Project at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:68) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:820) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158) at business.Project$$EnhancerByCGLIB$$abbb019d.toString(<generated>) at javax.swing.DefaultListCellRenderer.getListCellRendererComponent(Unknown Source) at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source) at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source) at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source) at javax.swing.JComponent.getPreferredSize(Unknown Source) at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source) at java.awt.Container.layout(Unknown Source) at java.awt.Container.doLayout(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validate(Unknown Source) at javax.swing.JLayeredPane.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at gui.MainGUI.setActiveJPanel(MainGUI.java:216) at gui.MainGUI.access$2(MainGUI.java:212) at gui.MainGUI$7.actionPerformed(MainGUI.java:182) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
The strange thing is that i can continou with my program, in other words the error occurs but the program doesnt crash completely.
Anyone an idea how to bypass this error?
Thanx…
June 7, 2006 at 7:39 am #253204
Haris PecoMemberIdentifier have to be unique in hibernate session .It is usually primary key in database
You can’t attach two instances objects with same indentifier to session
If you want that exists more breweries in oneproject you have change identifier in project
(probably to composite identifier <project_id,brewery-id> or similar)Best
-
AuthorPosts