Hello. I pretty new to using Hibernate. I have inherited a project which I believe worked on the old developers system. I dont know what I am doing wrong. I have for the most part just brought this project into MyEclipse and trying to get it working. Its a pretty simple web app. I can log in fine, so I am using the User.hbm.xml file without problem it seems (atleast to query for username and password). When I go in to edit a customer however, I crash on session.save() for the Customer object! Please help. The error is
org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator.
This is printed below that stack
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'Customer'.
I turned on show sql, and found this just above the exception:
Hibernate: select max(id) from Customer
When I try this query in the HQL editor, it works fine. So why in the world is it not working when I am running it? I am really hoping this is a simple problem, or an easy configuration issue. Thanks very much for helping me!
Here is my hibernate.cfg.xml file:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- <property name="hibernate.connection.datasource">-->
<!-- java:/comp/env/jdbc/SalesManagementSystem-->
<!-- </property>-->
<!-- mapping files -->
<property name="myeclipse.connection.profile">mssql2005</property>
<property name="connection.url">
jdbc:sqlserver://localhost:1433
</property>
<property name="connection.username">admin</property>
<property name="connection.password">admin</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="show_sql">true</property>
<mapping resource="com/gc/ot/domain/User.hbm.xml" />
<mapping resource="com/gc/ot/domain/CustomerType.hbm.xml" />
<mapping resource="com/gc/ot/domain/Customer.hbm.xml" />
<mapping resource="com/gc/ot/domain/Opportunity.hbm.xml" />
<mapping resource="com/gc/ot/domain/Product.hbm.xml" />
<mapping resource="com/gc/ot/domain/OpportunityProduct.hbm.xml" />
<mapping resource="com/gc/ot/domain/CustomerDocument.hbm.xml" />
<mapping resource="com/gc/ot/domain/Document.hbm.xml" />
</session-factory>
</hibernate-configuration>
Here is my Customer.hbm.xml file:
Code:
<?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.gc.ot.domain.Customer" table="Customer" schema="dbo" catalog="SalesManagementSystem">
<id name="id" column="id" type="integer">
<!-- <column name="id" sql-type="int" not-null="true" /> -->
<generator class="increment" />
</id>
<property name="name" type="string" column="name" />
<property name="pocName" type="string" column="pocName" />
<property name="pocPhone" type="string" column="pocPhone" />
<property name="pocEmail" type="string" column="pocEmail" />
<property name="numberOfUsers" type="string" column="numberOfUsers" />
<property name="financialRisk" type="string" column="financialRisk" />
<property name="location" type="string" column="location" />
<property name="geoRegion" type="string" column="geoRegion" />
<many-to-one name="customerType" outer-join="true" column="customerTypeId" lazy="false" />
<set name="documents" cascade="delete-orphan"
table="CustomerDocument" inverse="true" outer-join="true"
lazy="true">
<key column="customerId" foreign-key="id" />
<one-to-many class="com.gc.ot.domain.CustomerDocument" />
</set>
</class>
</hibernate-mapping>
This is my User.hbm.xml file, which atleast logs me in based on username and password.
Code:
<?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.gc.ot.domain.User" table="Users" schema="dbo" catalog="SalesManagementSystem">
<id name="id" column="id" type="integer">
<!-- <column name="id" sql-type="int" not-null="true" />-->
<generator class="increment" />
</id>
<property name="firstName" type="string" column="firstName" />
<property name="lastName" type="string" column="lastName" />
<property name="userName" type="string" column="userName" />
<property name="email" type="string" column="email" />
<property name="admin" type="boolean" column="admin" />
<property name="password" type="string" column="password" update="false"/>
</class>
</hibernate-mapping>
Let me know if you need any more info, or what else I can do to narrow down my problem. Maybe one of my concerns is guessing maybe this was done in Hibernate v2.1 and I think when I added Hibernate Capabilities to the project I let it choose 3.2, are there syntax changes in my mapping file causing problems?