-->
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: help with join
PostPosted: Fri Sep 15, 2006 2:21 am 
Beginner
Beginner

Joined: Sun Feb 12, 2006 12:19 am
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1

Mapping documents:
<!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.age.j.soft.hibernate.ReleaseScheduleBean" table="release_schedule">
<id name="releaseScheduleID" column="release_schedule_id">
<generator class="native" />
</id>
<many-to-one name="milestone" column="milestoneID" not-null="true"/>
<!-- <property name="milestoneID" column="milestone_id"/> -->
<property name="feature" column="feature"/>
</class>
</hibernate-mapping>

<!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.age.j.soft.hibernate.MilestoneBean" table="milestone">
<id name="milestoneID" column="milestone_id">
<generator class="native" />
</id>
<property name="productID" column="product_id"/>
<property name="tentativeDate" column="tentative_date" type="date"/>
<property name="number" column="number"/>
<property name="releaseDate" column="release_date" type="date"/>
<property name="maxVersion" column="max_version"/>
<property name="minVersion" column="min_version"/>
</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:

java.sql.SQLException: Unknown column 'releasesch0_.milestoneID' in 'field list'

com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
com.mysql.jdbc.Connection.execSQL(Connection.java:3004)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1128)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1222)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
org.hibernate.loader.Loader.doQuery(Loader.java:662)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2145)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
org.springframework.orm.hibernate3.HibernateTemplate$31.doInHibernate(HibernateTemplate.java:853)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:844)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:840)
com.age.j.soft.dao.ReleaseScheduleDAO.getReleaseSchedule(ReleaseScheduleDAO.java:18)
com.age.j.soft.action.ReleaseScheduleAction.prepare(ReleaseScheduleAction.java:17)

Name and version of the database you are using:
MySQL 4

The generated SQL (show_sql=true):

org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select releasesch0_.release_schedule_id as release1_4_0_, milestoneb1_.milestone_id as milestone1_5_1_, releasesch0_.milestoneID as mileston2_4_0_, releasesch0_.feature as feature4_0_, milestoneb1_.product_id as product2_5_1_, milestoneb1_.tentative_date as tentative3_5_1_, milestoneb1_.number as number5_1_, milestoneb1_.release_date as release5_5_1_, milestoneb1_.max_version as max6_5_1_, milestoneb1_.min_version as min7_5_1_ from release_schedule releasesch0_ inner join milestone milestoneb1_ on releasesch0_.milestoneID=milestoneb1_.milestone_id where milestoneb1_.product_id=? order by milestoneb1_.number]; nested exception is java.sql.SQLException: Unknown column 'releasesch0_.milestoneID' in 'field list


I'm trying to load all ReleaseSchedule beans and all their foreign key associated MilestoneBean by milestoneID for a productID.


(ArrayList<ReleaseScheduleBean>)this.getHibernateTemplate().find("from " + ReleaseScheduleBean.class.getName() + " as rsBean inner join rsBean.milestone as msBean where msBean.productID = ? order by msBean.number" , id);

Not sure what I'm doing wrong. I looked at the examples in the manual.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 8:28 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
I believe you are missing the class attribute for the many-to-one relationship. I.E
Code:
<many-to-one column="col" name="prop" class="name of related class" />


Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 16, 2006 10:01 am 
Beginner
Beginner

Joined: Sun Feb 12, 2006 12:19 am
Posts: 20
I tried the class attribute. Still doesn't work.

Shawn


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 16, 2006 10:24 am 
Beginner
Beginner

Joined: Sun Feb 12, 2006 12:19 am
Posts: 20
I figured it out. I had my column name wrong. Needed to be lower case and have an underscore in it.


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.