[英]HibernateException: Missing table error for a Join Table using Grails 2.0.2 on MS SQL legacy database
I am trying to get a many-to-many relationship working using Grails 2.0.1 on Windows 7. I have exhausted both Google, this site, and my Grails books. 我试图在Windows 7上使用Grails 2.0.1建立多对多关系。我已经用尽了Google,此站点和我的Grails书籍。 Nothing worked.
没事。 I am connecting to a MS SQL Server 2005 database that I have READ only privileges on and yes - it is a legacy database.
我正在连接到具有只读特权的MS SQL Server 2005数据库,是的-它是旧数据库。 Everything in the 2 individual tables works fine (views OK & all) but when I try to add the join table code I get an error:
2个单独的表中的所有内容都可以正常工作(视图正常且全部),但是当我尝试添加联接表代码时,出现错误:
org.hibernate.HibernateException: Missing table: dbo.IN_USR_DRAWING_PRIV org.hibernate.HibernateException:缺少表:dbo.IN_USR_DRAWING_PRIV
The table does indeed exist and I can see it fine using IntelliJ's IDEA 10.5 Data Sources view & the MS SQL Server Management Studio. 该表确实存在,我可以使用IntelliJ的IDEA 10.5数据源视图和MS SQL Server Management Studio很好地看到它。 The relevant part of the error is this (I can send more ... much more if needed) :
错误的相关部分是这样的(如果需要,我可以发送更多……更多):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; org.springframework.beans.factory.BeanCreationException:创建名称为'transactionManagerPostProcessor'的bean时出错:初始化bean失败; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'transactionManager'的bean时出错:在设置bean属性'sessionFactory'时无法解析对bean'sessionFactory'的引用; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed;
嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'sessionFactory'的bean时出错:调用init方法失败; nested exception is org.hibernate.HibernateException: Missing table: dbo.
嵌套的异常是org.hibernate.HibernateException:缺少表:dbo。
IN_USR_DRAWING_PRIV
Here are the 2 domain classes : 这是2个域类:
class Drawing {
static hasMany = [appusers:Appuser]
String id
String drawingId //this is in the join table
String drawingName
static transients = ['name']
void setName(String name) {
id = name
}
String getName() {
return id
}
static mapping = {
table name: "IN_DRAWING", schema: "dbo"
version false
id column: 'DRAWING_ID', generator:'identity', insertable:false, updateable:false
drawingId column: "`DRAWING_ID`",insertable:false, updateable:false //this is in the join table
drawingName column: "`DRAWING_NAME`"
appusers column: '`USR_ID`',
joinTable: 'IN_USR_DRAWING_PRIV'
}
} }
class Appuser {
static belongsTo = Drawing
static hasMany = [drawings:Drawing]
String id
String usrId //this is in the join table
String usrName
static transients = ['name']
void setName(String name) {
id = name
}
String getName() {
return id
}
static mapping = {
table name: 'IN_USR', schema: "dbo"
version false
id column:'USR_ID', generator:'identity', insertable:false, updateable:false //this is in the join table
drawings column: 'DRAWING_ID',
joinTable: 'IN_USR_DRAWING_PRIV'
usrName column: "`USR_NAME`"
}
} }
And here is the schema for the join table: 这是联接表的架构:
dbo.IN_USR_DRAWER_PRIV
USR_ID (PK, varchar(23), not null)
DRAWING_ID (PK, FK, varchar(23), not null)
PRIV_ID (PK, int, not null)
GRAG reports it has a composite key of all 3 columns, which it does along with a FK on DRAWING_ID. GRAG报告它具有所有3列的组合键,并与DRAWING_ID上的FK一起使用。
Solutions that I have tried : 我尝试过的解决方案:
Any hints/clues/solutions appreciated. 任何提示/线索/解决方案表示赞赏。
我通过直接使用Groovy SQL并传入T-SQL来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.