0

我在我的应用程序中不断收到连接到托管 SQL Server 2008 的“无效对象名称”。我可以使用字符串从应用程序查询数据库。但是,每当我使用 Hibernate 时,我都会收到此错误

//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'.

谁能告诉我发生了什么以及如何解决它,它必须是一个休眠问题。我尝试添加一个方案,然后我收到一条错误消息,指出不允许 Recruiter.dbo.Survey。没有更多的配置文件可供查看,谷歌为我提供了任何有用的东西。谢谢

4

1 回答 1

1

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.

于 2012-04-23T20:51:16.250 回答