I keep getting an ‘invalid object name’ connecting to a hosted SQL Server 2008 in my application. I can query the DB from the app using a string. However whenever I use Hibernate I get this error
//Calling Class
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(survey);
tx.commit(); <!--Blows up-->
session.close();
<hibernate-configuration>
<session-factory name="Persist">
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.password">xxxx</property>
<property name="hibernate.connection.url">jdbc:sqlserver://xxxx</property>
<property name="hibernate.connection.username">xxxx</property>
<property name="hibernate.default_catalog">xxxx</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<mapping class="com.springmvc.dao.Survey" resource="com/springmvc/dao/Survey.hbm.xml"/>
</session-factory>
</hibernate-configuration>
//Table Mapping
<hibernate-mapping>
<class name="com.springmvc.dao.Survey" table="Survey">
<id name="SurveyId" type="int">
<column name="SURVEYID" />
<generator class="assigned" />
</id>
<property name="SurveyName" type="java.lang.String">
<column name="SURVEYNAME" />
</property>
<property name="CreateDate" type="java.sql.Date">
<column name="CREATEDATE" />
</property>
<property name="IsActive" type="boolean">
<column name="ISACTIVE" />
</property>
</class>
</hibernate-mapping>
//The Error
org.hibernate.exception.SQLGrammarException: could not insert: [com.springmvc.dao.Survey]
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'Recruiter.Survey'.
Can any one tell me what is going on and how to fix it, It has to be a Hibernate problem. I have tried to add a scheme then I get an error saying that Recruiter.dbo.Survey is not allowed. There are no more config file to look over and google has supplied me w/ anything useful. Thanks
Your primary key SurveryId is having the generator class as “assigned”, you need to assign the key before calling Save in hibernate session. Are you doing that? If you dont want to generate then make it auto generated.