无效的对象名称hiberate 3.6 [英] Invalid object Name hiberate 3.6

查看:112
本文介绍了无效的对象名称hiberate 3.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中不断收到一个连接到托管SQL Server 2008的'无效对象名'。我可以使用字符串从应用程序查询数据库。然而,无论何时我使用Hibernate,我都会遇到这个错误。

  //调用类
SessionFactory sf = new Configuration()。configure ().buildSessionFactory();
会话会话= sf.openSession();
Transaction tx = session.beginTransaction();
session.save(survey);
tx.commit(); <! - 鼓起来 - >
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.Surveyresource =com / springmvc / dao / Survey.hbm.xml/>
< / session-factory>
< / hibernate-configuration>

//表格映射
< hibernate-mapping>
< class name =com.springmvc.dao.Surveytable =Survey>
< id name =SurveyIdtype =int>
< column name =SURVEYID/>
< generator class =assigned/>
< / id>
< property name =SurveyNametype =java.lang.String>
< column name =SURVEYNAME/>
< / property>
< property name =CreateDatetype =java.sql.Date>
< column name =CREATEDATE/>
< / property>
< property name =IsActivetype =boolean>
< column name =ISACTIVE/>
< / property>
< / class>
< / hibernate-mapping>

//错误
org.hibernate.exception.SQLGrammarException:无法插入:[com.springmvc.dao.Survey]
引起:com.microsoft.sqlserver。 jdbc.SQLServerException:无效的对象名称'Recruiter.Survey'。

任何人都可以告诉我发生了什么以及如何解决它,它必须是Hibernate问题。我试图添加一个计划,然后我得到一个错误,说Recruiter.dbo.Survey是不允许的。没有更多的配置文件可以查看,并且Google为我提供了任何有用的东西。感谢您的主键SurveryId将生成器类设置为分配,您需要在调用保存之前分配键休眠会话。你在做那个吗?如果你不想生成然后让它自动生成。


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.

这篇关于无效的对象名称hiberate 3.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆