抛出的错误:
exception org.apache.jasper.JasperException: Hibernate operation: could not initialize a collection: [com.hibernate.entity.Type.Books#3]; bad SQL grammar [select books0_.type_id as type7_1_, books0_.book_id as book1_1_, books0_.book_id as book1_0_, books0_.book_name as book2_3_0_, books0_.book_price as book3_3_0_, books0_.book_producer as book4_3_0_, books0_.book_descn as book5_3_0_, books0_.t_id as t6_3_0_ from book books0_ where books0_.type_id=?]; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]列名 'type_id' 无效。
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not initialize a collection: [com.hibernate.entity.Type.Books#3]; bad SQL grammar [select books0_.type_id as type7_1_, books0_.book_id as book1_1_, books0_.book_id as book1_0_, books0_.book_name as book2_3_0_, books0_.book_price as book3_3_0_, books0_.book_producer as book4_3_0_, books0_.book_descn as book5_3_0_, books0_.t_id as t6_3_0_ from book books0_ where books0_.type_id=?]; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]列名 'type_id' 无效。
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:223)
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:363)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:800)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:792)
com.hibernate.dao.TypeDAO.findIdByTypeName(TypeDAO.java:25)
com.hibernate.manager.TypeManagerImpl.findIdByTypeName(TypeManagerImpl.java:23)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
$Proxy2.findIdByTypeName(Unknown Source)
org.apache.jsp.addBookInfo_jsp._jspService(addBookInfo_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)我的2个hibernate配置文件:book.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >  <hibernate-mapping package="com.hibernate.entity">
<class
name="Book"
table="book"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="integer"
column="book_id"
>
<generator class="native"/>
</id> <property
name="BookName"
column="book_name"
type="string"
not-null="false"
length="50"
/>
<property
name="BookPrice"
column="book_price"
type="java.lang.Float"
not-null="true"
length="53"
/>
<property
name="BookProducer"
column="book_producer"
type="string"
not-null="false"
length="50"
/>
<property
name="BookDescn"
column="book_descn"
type="string"
not-null="false"
length="50"
/>
<many-to-one
name="T"
column="t_id"
class="Type"
not-null="true"
>
</many-to-one>
</class>
</hibernate-mapping>type.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="com.hibernate.entity">
<class
name="Type"
table="type"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="integer"
column="type_id"
>
<generator class="native"/>
</id> <property
name="TypeName"
column="type_name"
type="string"
not-null="false"
length="50"
/>
<set name="Books" inverse="true" lazy="false">
<key column="type_id"/>
<one-to-many class="Book"/>
</set>
</class>
</hibernate-mapping>查找方法:
public List findIdByTypeName(String Name){

String hql = "from Type as t where t.TypeName='"+Name+"'";

return this.getHibernateTemplate().find(hql);
}页面上的调用:
<%
Book book = new Book();
Type type = new Type();
apply app = new apply();String typename;
if(request.getMethod().equals("POST")){ type.setTypeName((String)request.getParameter("bookType"));
typename = type.getTypeName();
System.out.println(typename);
System.out.println(app.getTypeManager().findIdByTypeName(typename));
for(int i=0;i < app.getTypeManager().findIdByTypeName(typename).size();i++){
   type = (Type)app.getTypeManager().findIdByTypeName(typename).get(0);
}
book.setBookName((String)request.getParameter("bookName"));
//book.setBookPrice(Float.valueOf("bookPrice"));
book.setBookProducer((String)request.getParameter("bookProducer"));
book.setBookDescn((String)request.getParameter("bookDescn"));
book.setT(type);
type.addToBooks(book);
Session abc =app.getSessionFactory() ;
Transaction tx = abc.beginTransaction();
abc.save(type);
tx.commit(); 
         abc.close(); 
response.sendRedirect("main.jsp");

%>在页面上输入书的信息和类型,然后把数据插入到book表中,用的是双向一对多的关系。为什么会多出来一个select语句。里面的type_id在book表中是没有的,这里却出来了,怎么解决,高手帮忙!!!急。